C# 在visual C中为窗体添加边框颜色#

C# 在visual C中为窗体添加边框颜色#,c#,border,visual-c#-express-2010,C#,Border,Visual C# Express 2010,好的,我用以下代码制作了一个表单:this.FormBorderStyle=FormBorderStyle.None好,我还添加了一个边界半径代码: [DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")] private static extern IntPtr CreateRoundRectRgn ( int nLeftRect, // x-coordinate of upper-left corn

好的,我用以下代码制作了一个表单:
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))
这是:

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

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


请注意,在使用区域(GraphicsPath)构造函数时,不必使用pinvoke。同样的图形也可以方便地绘制边框。

我尝试过e.Graphics.DrawRectangle(Pens.Black,新矩形(0,0,宽度-1,高度-1));但边界仅在顶部和左侧。此外,边界不会随形状弯曲。我做错了什么?很明显,当表单不是矩形时,您不能使用DrawRectangle:)使用ClientSize.Width/Height并在CreateRoundRectRgn()调用中减去2或加1。好的,我一直在寻找,但我找不到任何东西……您能帮我吗?我不明白这个问题。你不知道如何使用Graphics.DrawLine和Graphics.drawlipse?不要期望只有一行代码,您必须编写更多的代码。4条直线和4个圆弧。当你创建一个非标准的UI时,这是正常的,它需要更多的工作。不,我只有15岁,而且我正在学习,所以我真的没有太多地使用draw事件…可能是重复的