繁体   English   中英

更改Windows窗体

[英]Changing Windows Form

我正在研究一种更改Windows窗体框周围的框架的方法。 我想使其透明或完全摆脱它。 我设法摆脱了图标,摆脱了最大化按钮,并限制了用户调整窗口大小的能力。 该栏与我要实现的视觉主题冲突。

所以问题-在Windows窗体应用程序中自定义窗体边框和顶部栏有什么好方法吗?

我要编辑的栏

FormBorderStyle选择正确的值,例如None

这可能对您要问的内容有些矫kill过正,但是可以解决...这是我创建的带有圆形边框的快速应用程序。 这不是全部代码,但是也许您会从中得到灵感。

首先,我删除FormBorderStyle(将其设置为None)并添加鼠标处理程序以允许移动表单。 下面的代码...

    public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
    [DllImportAttribute("user32.dll")]
    public static extern bool ReleaseCapture();
    public const int WM_NCLBUTTONDOWN = 0xA1;
    public const int HT_CAPTION = 0x2;


    private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            ReleaseCapture();
            SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
        }
    }

然后,我创建了一个粉红色的网格以显示为表单背景。 并将TransparencyKey属性设置为我想要透明的背景颜色的RGB值(在本例中为255,15,255)。

透明网格

然后,我使用图形模块绘制文字控件。

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
        // Set the starting coordinants for our graphics drawing
        int y = 0;
        int x = 0;
        // Set the end coordinants for our graphics drawing
        int width = this.Size.Width;
        int height = this.Size.Height;
        // Set our graphics options
        e.Graphics.InterpolationMode = XGraphics.xInterpolation;
        e.Graphics.SmoothingMode = XGraphics.xSmoothingMode;
        e.Graphics.CompositingMode = XGraphics.xComposingMode;
        e.Graphics.CompositingQuality = XGraphics.xComposingQuality;
        e.Graphics.PixelOffsetMode = XGraphics.xPixelOffsetMode;
        // Set the colors, positions, and gradient directions then draw our background

        using (LinearGradientBrush gpxBrush = XGraphics.GradientBrushOrientation(0, x, y, width, height))
        {
            // Create our color blender object
            ColorBlend gpxBlend = null;
            gpxBlend = new ColorBlend(4);
            gpxBlend.Colors = new Color[] { Color.FromArgb(255, 0, 100, 255), Color.FromArgb(205, 255, 240, 240),
            Color.FromArgb(255, 20, 100, 230), Color.FromArgb(105, 105, 100, 255)  };
            gpxBlend.Positions = new float[] { 0.0F, .45F, .55F, 1.0F };
            gpxBrush.InterpolationColors = gpxBlend;
            // Draw our background
            e.Graphics.FillEllipse(gpxBrush, x, y, width, height);
        }

        // Set the end coordinants for our graphics drawing
        width = this.Size.Width-5;
        height = this.Size.Height-5;

        using (LinearGradientBrush gpxBrush = XGraphics.GradientBrushOrientation(0, x, y, width, height))
        {
            // Create our color blender object
            ColorBlend gpxBlend = null;
            gpxBlend = new ColorBlend(2);
            gpxBlend.Colors = new Color[] { Color.White, Color.Gray };
            gpxBlend.Positions = new float[] { 0.0F, 1.0F };
            gpxBrush.InterpolationColors = gpxBlend;
            // Draw our background
            e.Graphics.FillEllipse(gpxBrush, x+5, y+5, width-5, height-5);
        }



        width = this.Size.Width / 2;
        height = this.Size.Height / 2;
        using (LinearGradientBrush gpxBrush = XGraphics.GradientBrushOrientation(0, x, y, width, height))
        {
            // Create our color blender object
            ColorBlend gpxBlend = null;
            gpxBlend = new ColorBlend(2);
            gpxBlend.Colors = new Color[] { Color.White, Color.Gray };
            gpxBlend.Positions = new float[] { 0.0F, 1.0F };
            gpxBrush.InterpolationColors = gpxBlend;
            // Draw our background
            e.Graphics.FillEllipse(gpxBrush, x + width / 2, y + height / 2, width, height);
        }

        width = (this.Size.Width / 2) - 5;
        height = (this.Size.Height / 2) - 5;
        using (LinearGradientBrush gpxBrush = XGraphics.GradientBrushOrientation(0, x, y, width-5, height-5))
        {
            // Create our color blender object
            ColorBlend gpxBlend = null;
            gpxBlend = new ColorBlend(4);
            gpxBlend.Colors = new Color[] { Color.FromArgb(255, 0, 100, 255), Color.FromArgb(205, 255, 240, 240),
            Color.FromArgb(255, 20, 100, 230), Color.FromArgb(105, 105, 100, 255)  };
            gpxBlend.Positions = new float[] { 0.0F, .45F, .55F, 1.0F };
            gpxBrush.InterpolationColors = gpxBlend;
            // Draw our background
            e.Graphics.FillEllipse(gpxBrush, (x + width / 2)  +7, (y + height / 2) + 7, width - 5, height - 5);
        }
    }

没有背景或表格边框

如您所见,现在没有边框,并且边缘是透明的。 只需确保添加一个按钮以退出应用程序,因为不再有“ X”选项! ;)

希望这对您有所帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM