c# button圆角
时间: 2023-07-27 07:21:38 浏览: 143
在 C# 中,你可以通过以下代码实现 Button 圆角效果:
```csharp
private void SetButtonRound(Button btn, int radius)
{
// 创建圆角矩形路径
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddArc(btn.ClientRectangle.Width - radius, 0, radius, radius, 270, 90);
path.AddArc(btn.ClientRectangle.Width - radius, btn.ClientRectangle.Height - radius, radius, radius, 0, 90);
path.AddArc(0, btn.ClientRectangle.Height - radius, radius, radius, 90, 90);
path.AddArc(0, 0, radius, radius, 180, 90);
path.CloseAllFigures();
// 设置按钮的 Region 属性
btn.Region = new Region(path);
}
```
其中,`btn` 表示要设置圆角效果的 Button 对象,`radius` 表示圆角半径。你可以将这个方法放在窗体的构造函数中,或者在 Button 的 Click 事件中调用,以实现圆角效果。
阅读全文
相关推荐















