首页 > 开发 > 综合 > 正文

C# 制作出任意不规则按钮

2024-07-21 02:28:40
字体:
来源:转载
供稿:网友

  c# 制作出任意不规则按钮! (原理根据背景图绘制button)

using system.drawing.drawing2d;
private void button3_paint(object sender, system.windows.forms.painteventargs e)
  { this.button3.cursor = cursors.hand;
         bitmap bmpbob =(bitmap)this.button3.image;     
      graphicspath graphicspath = calculatecontrolgraphicspath(bmpbob);
     this.button3.region = new region(graphicspath); 
  }
  private static graphicspath calculatecontrolgraphicspath(bitmap bitmap)
  {
  
   graphicspath graphicspath = new graphicspath(); 
 
   color colortransparent = bitmap.getpixel(0, 0);
 
   int colopaquepixel = 0;
 
   for(int row = 0; row < bitmap.height; row ++)
   {   
    colopaquepixel = 0;
  
    for(int col = 0; col < bitmap.width; col ++)
    {
   
     if(bitmap.getpixel(col, row) != colortransparent)
     {
     
      colopaquepixel = col;
   
      int colnext = col;
   
      for(colnext=colopaquepixel; colnext<bitmap.width; colnext++)
       if(bitmap.getpixel(colnext, row) == colortransparent)
        break;
    
      graphicspath.addrectangle(new rectangle(colopaquepixel,
       row, colnext - colopaquepixel, 1));
   
      col = colnext;
     }
    }
   } 
   return graphicspath;
  }

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表