我怎样才能得到一个圆形按钮?

Lis*_*isa 7 c# winforms

我想在WinForms中有一个圆形按钮控件,我该怎么做到这一点?第三方控件或代码示例没问题.

Han*_*ant 20

你可以很容易地创建自己的,Region属性使它变得简单.在项目中添加一个新类并粘贴下面显示的代码.编译.将新控件从工具箱顶部拖放到表单上.

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

class RoundButton : Button {
    protected override void OnResize(EventArgs e) {
        using (var path = new GraphicsPath()) {
            path.AddEllipse(new Rectangle(2, 2, this.Width - 5, this.Height - 5));
            this.Region = new Region(path);
        }
        base.OnResize(e);
    }
}
Run Code Online (Sandbox Code Playgroud)