2010-09-14 265 views
3

如何制作圆形的按钮而不是传统的矩形。圆形按钮

我使用的WinForms(2.0)

+0

你说的是ASP.NET,还是你在说WinForms。如果后者,我不知道。如果前者,这是一个CSS问题,谷歌“CSS圆角” – RPM1984 2010-09-14 10:45:01

回答

2

我需要基于默认的Windows窗体按钮来实现自己的Button类。 类似于thisthis。您可以使用谷歌查找更多的例子。

17

先做个班。给它命名圆形按钮。 然后直接写代码,因为这:

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

} 

然后构建应用程序,并关闭。 现在转到工具箱,您将看到一个名为RoundButton的控件。 然后药物,并将其放在你的Windows窗体上并测试它......享受!

+0

最简单的答案谢谢。 – Napster 2014-05-31 22:29:53