C#中怎么重写button让button显示为圆形

高分请高手,... 高分请高手, 展开
 我来答
匿名用户
推荐于2017-12-16
展开全部
给你找了一个。/// <summary>
/// 绘制圆形按钮
/// </summary>
public void DrawRoundButton(Graphics g)
{
GraphicsPath path = new GraphicsPath();
path = path=DrawButtonFade(this.buttonPath , g ,this.backColor, this.frontColor);
Region region = new Region(path);
this.Bounds = rectangle;
this.Region = region;

}/// <summary>
/// 绘制按下的按钮
/// </summary>
public void DrawPushedButton(Graphics g)
{
GraphicsPath path = new GraphicsPath();
path=DrawButtonFade(this.buttonPath , g ,this.frontColor , this.backColor);
Region region = new Region(path);
this.Bounds = rectangle;
this.Region = region;

}/// <summary>
/// 获取绘制按钮区域
/// </summary>
public void GetButtonRegion()
{
roundRect = new Rectangle(0,0,this.Width,this.Height);//设置画椭圆区域
rectangle = new Rectangle(this.Left,this.Top,this.Width,this.Height);//设定按钮显示位置和最大响应范围,只能是矩形
buttonCenter = new Point ((int)this.Width/2 , (int)this.Height/2); //绘制立体效果中心

}protected override void OnPaint(PaintEventArgs pevent)
{
// TODO: 添加 RoundButton.OnPaint 实现
base.OnPaint (pevent);
Graphics g = pevent.Graphics ;
GetButtonRegion();
if(this.isPushed != false)
this.DrawPushedButton(g);
else
this.DrawRoundButton(g);
}/// <summary>
/// 绘制不同形状的按钮
/// </summary>
public GraphicsPath DrawButtonFade(int fade, Graphics g, Color center, Color edge)
{
GraphicsPath path = new GraphicsPath();
switch(fade)
{
case 0:
path.AddEllipse(roundRect);//在路径中画椭圆
PathGradientBrush pthGrBrush0 = new PathGradientBrush(path);// 选取画刷
pthGrBrush0.CenterColor = center;
pthGrBrush0.CenterPoint = this.buttonCenter;
Color[] colors0 = {edge};
pthGrBrush0.SurroundColors = colors0;
g.FillEllipse(pthGrBrush0,roundRect);
break;
case 1:
path.AddRectangle(roundRect);//在路径中画矩形
PathGradientBrush pthGrBrush1 = new PathGradientBrush(path);// 选取画刷
pthGrBrush1.CenterColor = center;
pthGrBrush1.CenterPoint = this.buttonCenter;
Color[] colors1 = {edge};
pthGrBrush1.SurroundColors = colors1;
g.FillRectangle(pthGrBrush1,roundRect);
break;
case 2:
Point[] TriagleArray =
{
new Point(this.Width/2 , 0),
new Point(0,this.Height),
new Point(this.Width ,this.Height),
new Point(this.Width/2 , 0)
};
path.AddLines(TriagleArray);//在路径中画三角形
PathGradientBrush pthGrBrush2 = new PathGradientBrush(path);// 选取画刷
pthGrBrush2.CenterColor = center;
pthGrBrush2.CenterPoint = this.buttonCenter;
Color[] colors2 = {edge};
pthGrBrush2.SurroundColors = colors2;
g.FillRectangle(pthGrBrush2,roundRect);
break; default:
path.AddEllipse(roundRect);//默认:在路径中画椭圆
PathGradientBrush pthGrBrushDe = new PathGradientBrush(path);// 选取画刷
pthGrBrushDe.CenterColor = center;
pthGrBrushDe.CenterPoint = this.buttonCenter;
Color[] colorsDe = {edge};
pthGrBrushDe.SurroundColors = colorsDe;
g.FillEllipse(pthGrBrushDe,roundRect);
break; }
return path;

}
匿名用户
2013-06-06
展开全部
一般这种情况,都是用图片代替按钮的~~都有onclick事件啊~~
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2013-06-06
展开全部
贴一个图片
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式