• Winform 窗口圆角实现


          项目需要,得把Winform的窗口做成圆角,同时把标题栏等一堆东西去掉,做成如下的样子:

     

          首先,在新建Winform之后,在属性栏中, 把MaximizeBox和MinimizeBox 置为False,同时将ShowIcon置为False,FormBorderStyle置为None。之后,窗口就变成一块白板了。

          然后,PS出一张如上的背景图来,把图做成圆角。将改图设为Winform的背景,BackgroundImageLayout设为Stretch。

          网上有人说此后只需要将Winform的BackColor置为Color.Transparent就Ok了, 但是VS2010会报错,控件背景不允许使用透明色。

          所以只能学习网上有人提到的办法,实现Winform的Paint时间,将窗口重绘成圆角的。

           

    窗口圆角
      1         private void Main_Paint(object sender, PaintEventArgs e)
      2         {
      3             List<Point> list = new List<Point>();
      4             int width = this.Width;
      5             int height = this.Height;
      6 
      7             #region 四个圆角
      8 
      9             //左上  
     10             list.Add(new Point(047));
     11             list.Add(new Point(142));
     12             list.Add(new Point(238));
     13             list.Add(new Point(336));
     14             list.Add(new Point(433));
     15             list.Add(new Point(532));
     16             list.Add(new Point(629));
     17             list.Add(new Point(727));
     18             list.Add(new Point(826));
     19             list.Add(new Point(924));
     20             list.Add(new Point(1022));
     21             list.Add(new Point(1121));
     22             list.Add(new Point(1220));
     23             list.Add(new Point(1319));
     24             list.Add(new Point(1417));
     25             list.Add(new Point(1516));
     26             list.Add(new Point(1615));
     27             list.Add(new Point(1714));
     28             list.Add(new Point(1913));
     29             list.Add(new Point(2012));
     30             list.Add(new Point(2111));
     31             list.Add(new Point(2210));
     32             list.Add(new Point(249));
     33             list.Add(new Point(268));
     34             list.Add(new Point(277));
     35             list.Add(new Point(296));
     36             list.Add(new Point(325));
     37             list.Add(new Point(334));
     38             list.Add(new Point(363));
     39             list.Add(new Point(382));
     40             list.Add(new Point(421));
     41             list.Add(new Point(470));
     42 
     43             //右上  
     44             list.Add(new Point(width - 470));
     45             list.Add(new Point(width - 421));
     46             list.Add(new Point(width - 382));
     47             list.Add(new Point(width - 363));
     48             list.Add(new Point(width - 334));
     49             list.Add(new Point(width - 325));
     50             list.Add(new Point(width - 296));
     51             list.Add(new Point(width - 277));
     52             list.Add(new Point(width - 268));
     53             list.Add(new Point(width - 249));
     54             list.Add(new Point(width - 2210));
     55             list.Add(new Point(width - 2111));
     56             list.Add(new Point(width - 2012));
     57             list.Add(new Point(width - 1913));
     58             list.Add(new Point(width - 1714));
     59             list.Add(new Point(width - 1615));
     60             list.Add(new Point(width - 1516));
     61             list.Add(new Point(width - 1417));
     62             list.Add(new Point(width - 1319));
     63             list.Add(new Point(width - 1220));
     64             list.Add(new Point(width - 1121));
     65             list.Add(new Point(width - 1022));
     66             list.Add(new Point(width - 924));
     67             list.Add(new Point(width - 826));
     68             list.Add(new Point(width - 727));
     69             list.Add(new Point(width - 629));
     70             list.Add(new Point(width - 532));
     71             list.Add(new Point(width - 433));
     72             list.Add(new Point(width - 336));
     73             list.Add(new Point(width - 238));
     74             list.Add(new Point(width - 142));
     75             list.Add(new Point(width - 047));
     76 
     77             //右下  
     78             list.Add(new Point(width - 0, height - 47));
     79             list.Add(new Point(width - 1, height - 42));
     80             list.Add(new Point(width - 2, height - 38));
     81             list.Add(new Point(width - 3, height - 36));
     82             list.Add(new Point(width - 4, height - 33));
     83             list.Add(new Point(width - 5, height - 32));
     84             list.Add(new Point(width - 6, height - 29));
     85             list.Add(new Point(width - 7, height - 27));
     86             list.Add(new Point(width - 8, height - 26));
     87             list.Add(new Point(width - 9, height - 24));
     88             list.Add(new Point(width - 10, height - 22));
     89             list.Add(new Point(width - 11, height - 21));
     90             list.Add(new Point(width - 12, height - 20));
     91             list.Add(new Point(width - 13, height - 19));
     92             list.Add(new Point(width - 14, height - 17));
     93             list.Add(new Point(width - 15, height - 16));
     94             list.Add(new Point(width - 16, height - 15));
     95             list.Add(new Point(width - 17, height - 14));
     96             list.Add(new Point(width - 19, height - 13));
     97             list.Add(new Point(width - 20, height - 12));
     98             list.Add(new Point(width - 21, height - 11));
     99             list.Add(new Point(width - 22, height - 10));
    100             list.Add(new Point(width - 24, height - 9));
    101             list.Add(new Point(width - 26, height - 8));
    102             list.Add(new Point(width - 27, height - 7));
    103             list.Add(new Point(width - 29, height - 6));
    104             list.Add(new Point(width - 32, height - 5));
    105             list.Add(new Point(width - 33, height - 4));
    106             list.Add(new Point(width - 36, height - 3));
    107             list.Add(new Point(width - 38, height - 2));
    108             list.Add(new Point(width - 42, height - 1));
    109             list.Add(new Point(width - 47, height - 0));
    110 
    111             //左下  
    112             list.Add(new Point(47, height - 0));
    113             list.Add(new Point(42, height - 1));
    114             list.Add(new Point(38, height - 2));
    115             list.Add(new Point(36, height - 3));
    116             list.Add(new Point(33, height - 4));
    117             list.Add(new Point(32, height - 5));
    118             list.Add(new Point(29, height - 6));
    119             list.Add(new Point(27, height - 7));
    120             list.Add(new Point(26, height - 8));
    121             list.Add(new Point(24, height - 9));
    122             list.Add(new Point(22, height - 10));
    123             list.Add(new Point(21, height - 11));
    124             list.Add(new Point(20, height - 12));
    125             list.Add(new Point(19, height - 13));
    126             list.Add(new Point(17, height - 14));
    127             list.Add(new Point(16, height - 15));
    128             list.Add(new Point(15, height - 16));
    129             list.Add(new Point(14, height - 17));
    130             list.Add(new Point(13, height - 19));
    131             list.Add(new Point(12, height - 20));
    132             list.Add(new Point(11, height - 21));
    133             list.Add(new Point(10, height - 22));
    134             list.Add(new Point(9, height - 24));
    135             list.Add(new Point(8, height - 26));
    136             list.Add(new Point(7, height - 27));
    137             list.Add(new Point(6, height - 29));
    138             list.Add(new Point(5, height - 32));
    139             list.Add(new Point(4, height - 33));
    140             list.Add(new Point(3, height - 36));
    141             list.Add(new Point(2, height - 38));
    142             list.Add(new Point(1, height - 42));
    143             list.Add(new Point(0, height - 47));
    144 
    145             #endregion
    146 
    147             Point[] points = list.ToArray();
    148 
    149             GraphicsPath shape = new GraphicsPath();
    150             shape.AddPolygon(points);
    151 
    152             this.Region = new System.Drawing.Region(shape);
    153 
    154         }

           这样就把圆角窗口做出来了。需要说的是,这样设置出来的圆角是又毛刺的,精细程度跟你手动设置的点的个数有关,是个体力活。

           借鉴了别人的工作,致敬~

  • 相关阅读:
    JUC学习笔记--从阿里Java开发手册学习线程池的正确创建方法
    1.初识Python
    学会 Debug
    如何找出nginx配置文件的所在位置?
    一个技术人,如何做到比别人更突出
    生产环境如何快速跟踪、分析、定位问题-Java
    如何优化代码中大量的if/else,switch/case?
    UML类图几种关系的总结
    DateUtils常用方法
    如何存储和表示数字—二进制(一)
  • 原文地址:https://www.cnblogs.com/YFYkuner/p/2314921.html
Copyright © 2020-2023  润新知