C# winforms button with solid border, like 3d

2019-01-20 13:33发布

How can I create button with solid border(3d), like picture below on C# winforms?

3d-button

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.

1条回答
beautiful°
2楼-- · 2019-01-20 13:55

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:

enter image description here

查看更多
登录 后发表回答