c#高手进来,关于如何根据butten背景图片的形状自定义为按钮的形状

网上查了有关资料,但不知道具体怎么做,下面是代码:(我不知道把这段代码加到哪里去)usingSystem.Drawing.Drawing2D;privatevoidbut... 网上查了有关资料,但不知道具体怎么做,下面是代码:(我不知道把这段代码加到哪里去)
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;
}
没人回答吗??55555555555555555555
展开
 我来答
byscience
2010-10-20 · TA获得超过366个赞
知道小有建树答主
回答量:240
采纳率:0%
帮助的人:222万
展开全部
这个代码是用GDI+绘图来改变按钮的形状,但做起来太麻烦。一般不这样做。想要美观你可以用PictureBOx代替按钮
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式