代码改变世界

winform窗体显示圆角效果

2012-07-25 16:11  唐然  阅读(400)  评论(0编辑  收藏  举报

  首先添加引用:using System.Drawing.Drawing2D;

    主要方法

      private void Type(Control sender, int p_1, double p_2)
        {
            GraphicsPath oPath = new GraphicsPath();
            oPath.AddClosedCurve(new Point[] { new Point(0, sender.Height / p_1), new Point(sender.Width / p_1, 0), new Point(sender.Width - sender.Width / p_1, 0), new Point(sender.Width, sender.Height / p_1), new Point(sender.Width, sender.Height - sender.Height / p_1), new Point(sender.Width - sender.Width / p_1, sender.Height), new Point(sender.Width / p_1, sender.Height), new Point(0, sender.Height - sender.Height / p_1) }, (float)p_2);
            sender.Region = new Region(oPath);
        }

 

  在Paint和Resize事件中分别调用

  

 private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Type(this, 30, 0.1);

        }

        private void Form1_Resize(object sender, EventArgs e)
        {
            Type(this, 30, 0.1);
        }

 

30 0.1的值可以根据需要的效果设置。
移动电源推荐