C# WinForms - custom button unwanted border when form unselected

后端 未结 2 992
甜味超标
甜味超标 2020-12-07 22:41

I\'m having a problem with a custom button I have created in c# win forms.. The button appears fine when the form is selected but as soon as I click away from the form a bor

相关标签:
2条回答
  • 2020-12-07 23:15

    fuex's answer can remove border in theory, but there is a bug that sometimes button will still have focus cue after you change the button enable status.

    (I ran into this bug in .Net 4.0 and I don't know the bug is fixed or not in later versions).

    To work around this bug, you should disable the ShowFocusCues property:

    protected override bool ShowFocusCues => false; // return base.ShowFocusCues;
    
    0 讨论(0)
  • 2020-12-07 23:19

    When you're dealing with a custom button you should set:

    button.TabStop = false;
    button.FlatStyle = FlatStyle.Flat;
    button.FlatAppearance.BorderSize = 0;
    

    Then since ButtonBase doesn't support the border color on Color.Transparent, you can overcome the issue by setting an Argb color:

    button.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255); //transparent
    
    0 讨论(0)
提交回复
热议问题