0
下面是我使用的类和我的初始化问题的声明,我已经在我的设计上创建了一个按钮。那么,我将在我的代码修改,这样,我所做的类将应用到当前的按钮在当前按钮上应用RoundButton
public Form1()
{
InitializeComponent();
Application.DoEvents();
RoundButton _btn = new RoundButton();
EventHandler myHandler = new EventHandler(_btnLog_Click);
_btnLog = _btn;
}
class RoundButton:Button
{
GraphicsPath GetRoundPath(RectangleF _rect, int radius)
{
float r2 = radius/2f;
GraphicsPath _gp = new GraphicsPath();
_gp.AddArc(_rect.X, _rect.Y, radius, radius, 180, 90);
_gp.AddLine(_rect.X + r2, _rect.Y, _rect.Width - r2, _rect.Y);
_gp.AddArc(_rect.X + _rect.Width - radius, _rect.Y, radius, radius, 270, 290);
_gp.AddLine(_rect.Width, _rect.Y + r2, _rect.Width, _rect.Height - r2);
_gp.AddArc(_rect.X + _rect.Width - radius,
_rect.Y + _rect.Height - radius, radius, radius, 0, 90);
_gp.AddLine(_rect.Width - r2, _rect.Height, _rect.X + r2, _rect.Height);
_gp.AddArc(_rect.X, _rect.Y + _rect.Height - radius, radius, radius, 90, 90);
_gp.AddLine(_rect.X, _rect.Height - r2, _rect.X, _rect.Y + r2);
_gp.CloseFigure();
return _gp;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
RectangleF _rect = new RectangleF(0, 0, this.Width, this.Height);
GraphicsPath _gp = GetRoundPath(_rect, 1);
this.Region = new Region(_gp);
using (Pen _pen = new Pen(Color.CadetBlue, 1.75f))
{
_pen.Alignment = PenAlignment.Inset;
e.Graphics.DrawPath(_pen, _gp);
}
}
}
[按钮C#(WinForms)中的圆形边缘]的可能的重复(https://stackoverflow.com/questions/28486521/rounded-edges-in-button-c-sharp-winforms) – Plutonix
没有回答我的问题问题先生 – Gab
如果您通过设计人员添加了“RoundButton”,则在第一个片段中创建的“RoundButton”是不同的。那一个永远不会添加tot他控制集合,所以它不清楚你在 – Plutonix