我把窗体的FormborderStyle设为了None,想给窗体绘制个黑色边框,四个角是弧形,本人新手,在线等,有合适的分数全部相送

解决方案 »

  1.   

    这个问题真是困扰不少人,包括我,搞了好久
    重写WndProc方法,用API获取Windows消息绘制窗体的非客户区,网上没有找到C#的例子
    现在只有找一下C++的,查一下Win32编程的资料,可能会有所启发用API函数SystemParametersInfo获取Windows工作区的大小,然后给窗体的MaximumSize属性赋值,限定窗体的最大Size,这样就不会盖住任务栏了。
      

  2.   

    绘制4个圆角代码:
         public static Region CreateRoundRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidthEllipse, int nHeightEllipse)
            {
                GraphicsPath path = new GraphicsPath();
                path.AddArc(new Rectangle(nLeftRect, nTopRect, nWidthEllipse, nHeightEllipse), 180f, 90f);
                path.AddArc(new Rectangle((nRightRect - nWidthEllipse) - 1, nTopRect, nWidthEllipse, nHeightEllipse), -90f, 90f);
                path.AddArc(new Rectangle((nRightRect - nWidthEllipse) - 1, (nBottomRect - nHeightEllipse) - 1, nWidthEllipse, nHeightEllipse), 0f, 90f);
                path.AddArc(new Rectangle(nLeftRect, (nBottomRect - nHeightEllipse) - 1, nWidthEllipse, nHeightEllipse), 90f, 90f);
                path.CloseAllFigures();
                return new Region(path);
            }form1.Region = CreateRoundRectRgn(this.sideWidth, this.formTopOffset, (this.frmBase.ClientSize.Width + this.sideWidth) + 1, (this.frmBase.Height - this.sideWidth) + 1, RoundWidth, RoundHeight);
      

  3.   

    3楼已经给了大概思路,你再仔细调试一下,保证GraphicsPath是一个封闭的路径,貌似楼上给的代码不能保证生成封闭路径。然后在OnPaint当中画你的圆角。
      

  4.   

    你首先要明白什么是GraphicPath,Region,这类的概念。解决这个问题的本质就是给Form.Region设置一个合适的区域,啥意思呢,本来Form的外观是个矩形,现在为了解决的问题,四个角成了圆角,那么这个矩形必须将矩形的四个角裁剪成四个圆角,这就是Form.Region做的事情,而要构成四个角被裁剪成圆角的样子,那么你必须使用GraphicPath来创建一条路径,你想象一下,一笔画成一条你想要的Form的边框(四个角是圆角)应该怎么做,这个GraphicPath就做这个的。