winform button边框
时间: 2023-09-15 14:15:58 浏览: 52
Winform中的Button默认有边框,可以通过修改Button的FlatStyle属性来改变边框的样式。
以下是几种常见的边框样式:
1. Flat:没有立体感的边框,与背景颜色相同。
2. Popup:有立体感的边框,与背景颜色不同。
3. Standard:有立体感的边框,与背景颜色相同。
4. System:与系统主题一致的边框。
可以通过设置Button的FlatStyle属性来改变边框样式,例如:
button1.FlatStyle = FlatStyle.Flat;
button2.FlatStyle = FlatStyle.Popup;
button3.FlatStyle = FlatStyle.Standard;
button4.FlatStyle = FlatStyle.System;
另外,也可以通过设置Button的ForeColor属性来改变边框颜色,例如:
button1.ForeColor = Color.Red;
button2.ForeColor = Color.Green;
button3.ForeColor = Color.Blue;
button4.ForeColor = SystemColors.ControlText;
相关问题
winform button边框线条颜色
Winform button的边框线条颜色可以通过以下代码进行设置:
1. 在Winform窗体的设计器中选中需要设置边框颜色的按钮。
2. 在属性窗口中找到“FlatStyle”属性,并将其设置为“Flat”。
3. 在属性窗口中找到“FlatAppearance”属性,并展开它。
4. 在“FlatAppearance”属性下找到“BorderColor”属性,并点击它的值框,选择需要的颜色。
5. 设置完毕后,保存并运行程序,即可看到按钮边框颜色已经发生变化。
winform中button边框圆角
在 WinForms 应用程序中,如果需要将 Button 控件的边框变成圆角,可以通过以下步骤实现:
1. 在按钮控件的 `Paint` 事件中,使用 `GraphicsPath` 对象绘制一个圆角矩形,并使用 `Region` 对象将按钮的可见区域设置为这个圆角矩形。具体实现如下:
```csharp
private void button1_Paint(object sender, PaintEventArgs e)
{
// 绘制圆角矩形
GraphicsPath path = new GraphicsPath();
path.AddArc(0, 0, 20, 20, 180, 90);
path.AddLine(20, 0, button1.Width - 20, 0);
path.AddArc(button1.Width - 20, 0, 20, 20, 270, 90);
path.AddLine(button1.Width, 20, button1.Width, button1.Height - 20);
path.AddArc(button1.Width - 20, button1.Height - 20, 20, 20, 0, 90);
path.AddLine(button1.Width - 20, button1.Height, 20, button1.Height);
path.AddArc(0, button1.Height - 20, 20, 20, 90, 90);
path.AddLine(0, button1.Height - 20, 0, 20);
// 设置按钮的可见区域为圆角矩形
button1.Region = new Region(path);
}
```
在上面的代码中,我们使用了 `GraphicsPath` 对象绘制了一个圆角矩形,然后使用 `Region` 对象将按钮的可见区域设置为这个圆角矩形。其中,`AddArc` 方法用于绘制圆角,`AddLine` 方法用于绘制直线连接圆角,从而形成一个完整的圆角矩形。
2. 如果需要让按钮的背景色和边框颜色也变成圆角的形状,可以在按钮的 `MouseEnter` 和 `MouseLeave` 事件中分别设置按钮的背景色和边框颜色。具体实现如下:
```csharp
private void button1_MouseEnter(object sender, EventArgs e)
{
// 鼠标移入时设置按钮的背景色和边框颜色
button1.BackColor = Color.FromArgb(255, 240, 240, 240);
button1.FlatAppearance.BorderColor = Color.FromArgb(255, 180, 180, 180);
}
private void button1_MouseLeave(object sender, EventArgs e)
{
// 鼠标移出时恢复按钮的背景色和边框颜色
button1.BackColor = Color.FromArgb(255, 220, 220, 220);
button1.FlatAppearance.BorderColor = Color.FromArgb(255, 200, 200, 200);
}
```
在上面的代码中,我们使用了 `BackColor` 属性和 `FlatAppearance.BorderColor` 属性来设置按钮的背景色和边框颜色,从而让按钮的背景色和边框颜色也变成了圆角的形状。