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

来源:网络整理 责任编辑:栏目编辑 发表时间:2013-07-01 05:14 点击:

  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;
  }

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • 浅析.NET下XML数据访问新机制
    • asp.net 面试+笔试题目第1/2页
    • C# 邮件地址是否合法的验证
    • asp.net 设置GridView的选中行的实现代码
    • C#高级编程:数据库连接[1]
    • 经典C++程序1
    • IIS 自动回收导致后台定时器失效的问题解决
    • ASP.NET&#160;GridView列表代码示例
    • Asp.net MVC源码分析--Action Filter的链式调用
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1