WinForm自定义弹出框边角圆滑处理

来源:互联网 发布:炭知天下龙泽路手机号 编辑:程序博客网 时间:2024/05/01 21:02

在使用C#制作Winform窗体时候,如果自定义窗体外观,需要对于Form做圆角处理,使得窗体更加美观。进行圆角处理的方法如下:

        /// <summary>        /// 去除Form的四角,使其变成圆角显示。切去3像素的大小。        /// <para>注意:使用此方法,要设置Form的BackgroundImageLayout属性为Stretch。</para>        /// <para>未设置的情况下,会产生页面闪烁。</para>        /// </summary>        /// <param name="form"></param>        public static void Paint(Form form)        {            var list = new List<Point>();            int width = form.Width;            int height = form.Height;            //左上            list.Add(new Point(0, 2));            list.Add(new Point(1, 2));            list.Add(new Point(1, 1));            list.Add(new Point(2, 1));            list.Add(new Point(2, 0));            //右上            list.Add(new Point(width - 2, 0));            list.Add(new Point(width - 2, 1));            list.Add(new Point(width - 1, 1));            list.Add(new Point(width - 1, 2));            list.Add(new Point(width - 0, 2));            //右下            list.Add(new Point(width - 0, height - 2));            list.Add(new Point(width - 1, height - 2));            list.Add(new Point(width - 1, height - 1));            list.Add(new Point(width - 2, height - 1));            list.Add(new Point(width - 2, height - 0));            //左下            list.Add(new Point(2, height - 0));            list.Add(new Point(2, height - 1));            list.Add(new Point(1, height - 1));            list.Add(new Point(1, height - 2));            list.Add(new Point(0, height - 2));            Point[] points = list.ToArray();            var shape = new GraphicsPath();            shape.AddPolygon(points);            //将窗体的显示区域设为GraphicsPath的实例             form.Region = new Region(shape);        }


0 0