C# winforms button with solid border, like 3d

后端 未结 3 1694
无人及你
无人及你 2020-12-06 13:53

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

\"3d-button\"

Panel <

3条回答
  •  攒了一身酷
    2020-12-06 14:03

    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:

提交回复
热议问题