如何获得圆形按钮? [英] How can I get a round button?

查看:63
本文介绍了如何获得圆形按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在WinForms中有一个圆形按钮控件,我怎么能做到这一点?可以使用第三方控件或代码示例。

I would like to have a round button control in WinForms, how might I accomplish this? A third-party control or code sample would be fine.

推荐答案

您可以很轻松地制作自己的代码,使用Region属性即可简单。在您的项目中添加一个新类,并粘贴以下代码。编译。将新控件从工具箱的顶部拖放到窗体上。

You can make your own pretty easily, the Region property makes it simple. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto a form.

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);
    }
}

这篇关于如何获得圆形按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆