Reputation: 7258
How do you remove the dotted line that appears on buttons when they are selected (either via tab or by clicking them)?
This question is for winforms
- any help is appreciated.
Edit: I apologize for the duplicate question. I did search for an answer, but I did not know this issue was due to the 'focus' of the button. As I result I was not finding the appropriate answers.
Upvotes: 9
Views: 4333
Reputation: 159
The only answer here that really works without having to hack (moving focus to another control) is Wongsathon Tuntanakan's answer.
I refer to his answer and, as a bit of extra, I've converted his code to VB:
Public Class YourButtonClass
Inherits System.Windows.Forms.Button
Protected Overrides ReadOnly Property ShowFocusCues As Boolean
Get
Return False
End Get
End Property
End Class
Upvotes: 0
Reputation: 71
create custom control add ShowFocusCues and build to use
Example
public class button : System.Windows.Forms.Button
{
protected override bool ShowFocusCues
{
get
{
return false;
}
}
}
Upvotes: 1
Reputation: 4463
This happens because your Button
gains focus. It is possible to remove it but that means giving the focus to something else when your button's focus Enter event is triggered.
private void button1_Enter(object sender, EventArgs e)
{
// give focus to something else
}
The problem with that is that you lose the ability to use the keyboard in order to select the button (using tab).
Moreover, a more correct approach would be to give focus to the last control that had focus instead of passing it fixed one.
Upvotes: 1
Reputation: 10552
have you tried to remove the focus from the button.
just call Focus();
when the button is clicked.
Upvotes: 1
Reputation: 8107
Look for button border settings.
I do not get this border, if I set the BorderSize
to 0
in the FlatAppearance
section
From Remove button border on tab c# winforms
Upvotes: 0