6

I have a button on my form that has flat style applied and uses a background image, I have removed all borders from the button, but when I tab onto the button from another control a black border appears around the button.

This can be seen in the image below. On the left is the button with black border on the right is a different button but shows how the cancel button should look.

Buttons

shane12195
  • 87
  • 1
  • 1
  • 7
  • 1
    Possible duplicate: http://stackoverflow.com/questions/148729/how-to-set-change-remove-focus-style-on-a-button-in-c – James Gaunt Apr 01 '12 at 17:21
  • You have to do something reasonable to indicate the focus. Which is what the black rectangle is intended to do. Completely removing it just gets users lost and frustrated when using your UI. – Hans Passant Apr 01 '12 at 17:37
  • I agree with hans, even if you remove the border, you should think of adding a highlight (image change with a brighter one on focus or something else). working around with UI that users are used to is not a good idea unless you are 100% sure what you are doing. – Dumbo Apr 02 '12 at 14:04
  • @Sean87 Hi Sean & Hans, I do intend on adding a highlight to the button when it is selected, I would leave the border only it doesn't look good. – shane12195 Apr 03 '12 at 00:31

5 Answers5

3

I do not get this border, if I set the BoderSize to 0 in the FlatAppearance section.


Further investigation shows that this border appears only when the button is the default button. You can create your own button, which does never show this border like this

public class NoNotifyButton: System.Windows.Forms.Button
{
    public override void NotifyDefault(bool value)
    {
    }
}

Note: NotifyDefault remains intentionally empty.

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
  • Hi, I tried doing this using the method here (its the highlighted answer) http://social.msdn.microsoft.com/Forums/da-DK/winforms/thread/8d85e6dd-18ad-4503-9f0a-731a8d73d570 But the problem still persists. – shane12195 Apr 03 '12 at 00:30
  • Note: There is a black border, which is drawn around the default button and a gray border, which is drawn around focused buttons. My code makes the black border disappear; however, the gray one remains. – Olivier Jacot-Descombes Apr 03 '12 at 15:02
2

You have to make a new button class using IButtonControl and change NotifyDefault to false:

base.NotifyDefault(false);
Dumbo
  • 13,555
  • 54
  • 184
  • 288
1

You don't have to create a derived class. You can set the ForeColor to be the same as parent control BackColor. As follows :

btn1.ForeColor = btn1.Parent.BackColor;
Amit Lipman
  • 687
  • 7
  • 19
0

You can do it setting the button property "ForeColor" to transparent

0

I managed to get around this by setting the button TabStop property to False and then using this code on the button click event

private void sendBackTab()
        {
            System.Windows.Forms.SendKeys.SendWait("+{TAB}");
        }
cbyte
  • 681
  • 7
  • 12