C#创建不规则窗体的4种方式详解

2019-12-30 11:01:57丽君
  • ///从找到的不透明点开始,继续寻找不透明点,一直到找到或则达到图片宽度   for (colNext = colOpaquePixel; colNext < bitmap.Width; colNext++)  
  • if (bitmap.GetPixel(colNext, row) == colorTransparent)   break;  
  • // Form a rectangle for line of opaque pixels found and add it to our graphics path   //将不透明点加到graphics path  
  • graphicsPath.AddRectangle(new Rectangle(colOpaquePixel, row, colNext - colOpaquePixel, 1));   // No need to scan the line of opaque pixels just found  
  • col = colNext;   }  
  • }   }  
  • // Return calculated graphics path   return graphicsPath;  
  • }   }  

    4.运行

    三、调用类库实现

    主要就是根据一些坐标,然后根据这些坐标绘制窗体

    代码如下:

     

     
    1. public Form3()   {  
    2. InitializeComponent();   //创建不规则窗体  
    3. POINTAPI[] poin;   poin = new POINTAPI[5];  
    4. poin[0].x = 90;   poin[0].y = 90;  
    5. poin[1].x = this.Width;   poin[1].y = 0;  
    6. poin[2].x = Width;   poin[2].y = this.Height / 2;  
    7. poin[3].x = Width / 2;   poin[3].y = Height / 2;