C#开发实战随笔----001 圆形按钮设计
在做尤其desktop software design的时候很多时候方形的button是缺少美感。
这篇文章主要来讲述了如何自定义一个圆形的按钮来触发事件。
第一步:
(图1)
先新建一个class如图1所示
然后代码如下,代码主要利用 system.Drawing.Drawing2D来绘制椭圆(正圆),并且继承了所有按钮的特性。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace BillTracking
{
class roundButton : Button
{
protected override void OnPaint(PaintEventArgs pevent)
{
GraphicsPath graphics = new GraphicsPath();
graphics.AddEllipse(0, 0, ClientSize.Width, ClientSize.Height);
this.Region = new System.Drawing.Region(graphics);
base.OnPaint(pevent);
base.OnPaint(pevent);
}
}
}