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;
}
作者:gdgzboy@牛C网
地址:http://www.niuc.net/post/3025/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
BASE64编码规则及C#实现
如何用正确的方法写出高质量软件的75条体会
.net 中委托与事件的理解
ASP.Net生成业务数据的统计图形
ASP.NET中实现Flash与.NET的紧密集成
ASP.NET默认的上传组件支持进度条反映
讲解ASP.NET中如何防范SQL注入式攻击
解决ASP.NET的进程帐户没有访问 IIS的权限
VS.NET2005 beta2 中DataSet的二进制序列化
新手教程-手把手教你学Web Services 教程
ASP.NET页面事件
ASP.NET 生成 RSS Feed





