C sharp中button如何设置圆角
时间: 2023-10-19 11:07:25 浏览: 76
要在C#中为按钮设置圆角,可以使用以下代码:
```
button1.FlatStyle = FlatStyle.Flat;
button1.FlatAppearance.BorderSize = 0;
button1.FlatAppearance.MouseDownBackColor = Color.Transparent;
button1.FlatAppearance.MouseOverBackColor = Color.Transparent;
button1.BackColor = Color.Blue; //设置按钮背景色
button1.ForeColor = Color.White; //设置按钮前景色
GraphicsPath path = new GraphicsPath();
path.AddEllipse(0, 0, button1.Width, button1.Height);
button1.Region = new Region(path);
```
上述代码将按钮的FlatStyle属性设置为Flat,将按钮的边框大小设置为0,并将鼠标悬停和按下时的背景颜色设置为透明。然后,创建一个GraphicsPath对象,将按钮的区域设置为圆形,最后将该区域分配给按钮的Region属性。
阅读全文