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

高分请高手,... 高分请高手, 展开
 我来答
dbqoopdb
推荐于2016-09-15 · TA获得超过1730个赞
知道大有可为答主
回答量:1449
采纳率:53%
帮助的人:1420万
展开全部
using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace WindowsApplication1
{
/// <summary>
/// Summary description for cilpButton.
/// </summary>
public class cilpButton : System.Windows.Forms.Button
{
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddEllipse(0,0, this.Width, this.Height);
this.Region = new Region(path);
}

protected override void OnMouseEnter(EventArgs e)
{
Graphics g = this.CreateGraphics();
g.DrawEllipse(new Pen(Color.Red), 0, 0 , this.Width, this.Height);
g.Dispose();
}
protected override void OnMouseLeave(EventArgs e)
{
Graphics g = this.CreateGraphics();
g.DrawEllipse(new Pen(this.BackColor), 0, 0 , this.Width, this.Height);
g.Dispose();
}

protected override void OnPaintBackground(PaintEventArgs pevent)
{
Pen pen = new Pen(this.BackColor);
Graphics g = this.CreateGraphics();
g.Clear(Color.Goldenrod);
g.FillEllipse(Brushes.DarkKhaki, new Rectangle(0,0, this.Width, this.Height));
}

protected override void OnMouseDown(MouseEventArgs e)
{
OnPaintBackground(null);
}
protected override void OnMouseUp(MouseEventArgs e)
{
this.OnClick(e);//响应click事件.
}
}
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式