首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在visual C#中的窗体上添加边框颜色

在visual C#中的窗体上添加边框颜色
EN

Stack Overflow用户
提问于 2012-05-20 22:44:40
回答 1查看 1.6K关注 0票数 0

好的,我已经用这个代码做了一个表单:this.FormBorderStyle = FormBorderStyle.None;好的,我还用这个代码添加了一个边界半径:

代码语言:javascript
运行
复制
[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));和这个:

代码语言:javascript
运行
复制
ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, Color.Black, ButtonBorderStyle.Solid);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-20 22:57:58

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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10674383

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档