小智 27
先上课.给它命名圆形按钮.然后直接编写代码:
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Linq;
using System.Text;
namespace WindowsFormsApplication1
{
public class RoundButton : Button
{
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
GraphicsPath grPath = new GraphicsPath();
grPath.AddEllipse(0, 0, ClientSize.Width, ClientSize.Height);
this.Region = new System.Drawing.Region(grPath);
base.OnPaint(e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后构建您的应用程序并关闭它.现在转到工具箱,您将看到一个名为RoundButton的控件.然后药物并将其放在您的窗体上并测试它......享受!
代码项目中有许多有关这类事情的文章,特别是“ RoundButton Windows Control-Every Decreasing Circles”一文可能引起人们的兴趣,因为它表明您必须执行不同种类的圆形按钮。
GraphicsPath p = new GraphicsPath();
p.AddEllipse(1, 1, button1.Width - 4, button1.Height - 4);
button1.Region = new Region(p);
Run Code Online (Sandbox Code Playgroud)