zoukankan      html  css  js  c++  java
  • C#winform圆角窗体绘制

    一、下面是一个绘制方法的静态类

    废话不说直接上代码:

    using System;
    using System.Collections.Generic;
    using System.Text;

    //其它命名空间
    using System.Windows.Forms;
    using System.Drawing;
    using System.Drawing.Drawing2D;

    namespace Tools.UserClass
    {
        public static class RoundFormPainter
        {
            public static void Paint(this object sender, PaintEventArgs e)
            {
                Form form = ((Form)sender);
                List<Point> list = new List<Point>();
                int width = form.Width;
                int height = form.Height;

                //左上
                list.Add(new Point(0, 5));
                list.Add(new Point(1, 5));
                list.Add(new Point(1, 3));
                list.Add(new Point(2, 3));
                list.Add(new Point(2, 2));
                list.Add(new Point(3, 2));
                list.Add(new Point(3, 1));
                list.Add(new Point(5, 1));
                list.Add(new Point(5, 0));
                //右上
                list.Add(new Point(width - 5, 0));
                list.Add(new Point(width - 5, 1));
                list.Add(new Point(width - 3, 1));
                list.Add(new Point(width - 3, 2));
                list.Add(new Point(width - 2, 2));
                list.Add(new Point(width - 2, 3));
                list.Add(new Point(width - 1, 3));
                list.Add(new Point(width - 1, 5));
                list.Add(new Point(width - 0, 5));
                //右下
                list.Add(new Point(width - 0, height - 5));
                list.Add(new Point(width - 1, height - 5));
                list.Add(new Point(width - 1, height - 3));
                list.Add(new Point(width - 2, height - 3));
                list.Add(new Point(width - 2, height - 2));
                list.Add(new Point(width - 3, height - 2));
                list.Add(new Point(width - 3, height - 1));
                list.Add(new Point(width - 5, height - 1));
                list.Add(new Point(width - 5, height - 0));
                //左下
                list.Add(new Point(5, height - 0));
                list.Add(new Point(5, height - 1));
                list.Add(new Point(3, height - 1));
                list.Add(new Point(3, height - 2));
                list.Add(new Point(2, height - 2));
                list.Add(new Point(2, height - 3));
                list.Add(new Point(1, height - 3));
                list.Add(new Point(1, height - 5));
                list.Add(new Point(0, height - 5));

                Point[] points = list.ToArray();

                GraphicsPath shape = new GraphicsPath();
                shape.AddPolygon(points);

                //将窗体的显示区域设为GraphicsPath的实例
                form.Region = new System.Drawing.Region(shape);
            }
        }
    }

    二、调用

    1窗体的FormBorderStyle属性设置为None

    2在窗体Paint事件中加入以下代码

       Tools.UserClass.RoundFormPainter.Paint(sender, e);

  • 相关阅读:
    86. Partition List
    2. Add Two Numbers
    55. Jump Game
    70. Climbing Stairs
    53. Maximum Subarray
    64. Minimum Path Sum
    122. Best Time to Buy and Sell Stock II
    以场景为中心的产品设计方法
    那些产品经理犯过最大的错
    Axure教程:如何使用动态面板?动态面板功能详解
  • 原文地址:https://www.cnblogs.com/xuchonglei/p/1896408.html
Copyright © 2011-2022 走看看