How can I get a round button? [closed]

2020-02-01 21:39发布

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.

标签: c# winforms
6条回答
时光不老,我们不散
2楼-- · 2020-02-01 22:07

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);
    }
}
查看更多
来,给爷笑一个
4楼-- · 2020-02-01 22:16

Use WPF if its still early in the project and you can still switch

查看更多
beautiful°
5楼-- · 2020-02-01 22:33

I suggest following two DLL files: PresentationCore.dll and PresentationFramework.dll

It's more commonly known as Windows Presentation Foundation (WPF), and can easily be used to make round buttons.

查看更多
▲ chillily
6楼-- · 2020-02-01 22:34

add custom drawing in OnPaint event handler.

查看更多
ら.Afraid
7楼-- · 2020-02-01 22:34

You'd probably have to create an image with your rounded corners specification, and use it on an image button to achieve what you want.

查看更多
登录 后发表回答