本文介绍了具有实心边框的C#winforms按钮,例如3d的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何创建带有纯边框(3d)的按钮,如下面的C#winforms图片所示?
面板 BorderStyle
可以设置为 Fixed3D
,但是按钮 BorderStyle
不能设置为 Fixed3D
。
我也已经尝试过 FlatAppearance
实际上是平面样式。
解决方案
您可以通过以下方式自定义 Button
控件,使其具有较粗的3d边框:
- 将按钮
FlatStyle
设置为Flat
- 在
FlatApperanace
中将BorderSize
设置为0
- 在
FlatApperanace
中将MouseOverBackColor
设置为ControlLight
然后处理 Paint
事件并使用
How can I create button with solid border(3d), like picture below on C# winforms?
Panel BorderStyle
can be set as Fixed3D
, but buttons BorderStyle
cannot be set as Fixed3D
.
I also already tried FlatAppearance
which is actualy flat style.
解决方案
You can customize the Button
control this way have thick 3d borders:
- Set the Button
FlatStyle
to beFlat
- In the
FlatApperanace
setBorderSize
to0
- In the
FlatApperanace
setMouseOverBackColor
toControlLight
Then handle Paint
event and using ControlPaint.DrawBorder
draw a thick 3d border:
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);
}
And here is the result:
这篇关于具有实心边框的C#winforms按钮,例如3d的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!