分享

电脑培训C# 制作出任意不规则按钮!

 昵称31500 2007-06-17

电脑培训C# 制作出任意不规则按钮!

 

来源:http://www./ArticleView/2007-1-9/Article_View_881.Htm

 

 

(原理根据背景图绘制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;
  }

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多