繁体   English   中英

在可视C#中的表单上添加边框颜色

[英]Adding a border color on a form in visual C#

好的,我用以下代码制作了一个表单: this.FormBorderStyle = FormBorderStyle.None; 好的,我还使用以下代码添加了边框半径:

[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
    private static extern IntPtr CreateRoundRectRgn
    (
        int nLeftRect, // x-coordinate of upper-left corner
        int nTopRect, // y-coordinate of upper-left corner
        int nRightRect, // x-coordinate of lower-right corner
        int nBottomRect, // y-coordinate of lower-right corner
        int nWidthEllipse, // height of ellipse
        int nHeightEllipse // width of ellipse
     );

    public Form4()
    {
        InitializeComponent();
        Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));
    }

因此,我需要在围绕边框半径弯曲的窗体周围添加一个小的黑色边框。 我怎么做?

好的,我添加了它,它可以正常工作,但是它不与边框配合使用,只是e.Graphics.DrawRectangle(Pens.Black, new Rectangle(0, 0, Width - 1, Height - 1));e.Graphics.DrawRectangle(Pens.Black, new Rectangle(0, 0, Width - 1, Height - 1)); 和这个:

ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, Color.Black, ButtonBorderStyle.Solid);

重写窗体的OnPaintBackground()方法,并使用传递的e.Graphics对象,使用Graphics方法简单地绘制边框。

请注意,当您使用Region(GraphicsPath)构造函数时,您不必固定电话。 相同的GraphicsPath也会很方便地绘制边框。

暂无
暂无

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

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