带有实心边框的 C# winforms 按钮,如 3d [英] C# winforms button with solid border, like 3d

查看:21
本文介绍了带有实心边框的 C# winforms 按钮,如 3d的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 C# winforms 上创建带有实心边框(3d)的按钮,如下图所示?

Panel BorderStyle 可以设置为Fixed3D,但是按钮BorderStyle 不能设置为Fixed3D.

我也已经尝试过 FlatAppearance 这实际上是平面样式.

解决方案

您可以通过这种方式自定义 Button 控件具有粗 3d 边框:

  • 设置按钮FlatStyleFlat
  • FlatApperanace中设置BorderSize0
  • 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 be Flat
  • In the FlatApperanace set BorderSize to 0
  • In the FlatApperanace set MouseOverBackColor to ControlLight

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆