如何在 C# winforms 上创建带有实线边框 (3d) 的按钮,如下图所示?
面板BorderStyle
可以设置为Fixed3D
,但是按钮BorderStyle
不能设置为Fixed3D
。
我也已经尝试过 FlatAppearance
,它实际上是平面样式。
最佳答案
您可以通过这种方式自定义 Button
控件,使其具有较厚的 3d 边框:
- 将按钮
FlatStyle
设置为Flat
- 在
FlatApperanace
中将BorderSize
设置为0
- 在
FlatApperanace
中将MouseOverBackColor
设置为ControlLight
然后处理Paint
事件并使用ControlPaint.DrawBorder
画一个粗的 3d 边框:
private void button1_Paint(object sender, PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics, button1.ClientRectangle,
SystemColors.ControlLightLight, 5, ButtonBorderStyle.Outset,
SystemColors.ControlLightLight, 5, ButtonBorderStyle.Outset,
SystemColors.ControlLightLight, 5, ButtonBorderStyle.Outset,
SystemColors.ControlLightLight, 5, ButtonBorderStyle.Outset);
}
结果如下:
关于具有实心边框的 C# winforms 按钮,如 3d,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37484556/