9

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.

enter image description here

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.

Mike Baxter
  • 6,868
  • 17
  • 67
  • 115
  • 6
    Why has this question been voted to be closed? It is a valid question. – Mike Baxter Mar 28 '13 at 13:29
  • When a button is 'selected'. Try tabbing through a windows forms application until a button is selected - you'll see the dotted line that I am referring to. – Mike Baxter Mar 28 '13 at 13:31
  • what you are asking is a method to override the default on focus behavior of the button control. You basically have to sub-class or override the default handling of button's WindowProcedure so that you can do your own painting when processing the windows message WM_PAINT – Davide Piras Mar 28 '13 at 13:32
  • Developers tend to be highly objective "T"'s (see myers-briggs). Start talking about feelings might as well slap on the scarlet letter. Consider re-phrasing your questions with technical details as opposed to how you feel about the outcome. – P.Brian.Mackey Mar 28 '13 at 13:34
  • 3
    The zeal found on Stack Overflow can be staggering at times... – Mike Baxter Mar 28 '13 at 13:38
  • 2
    From an accessible point-of-view you shouldn't remove the UI showing where the focus is. In this case, how do you know where the focus is using only your keyboard? – Michaël Hompus Mar 28 '13 at 13:39

6 Answers6

1

have you tried to remove the focus from the button.

just call Focus(); when the button is clicked.

string.Empty
  • 10,393
  • 4
  • 39
  • 67
1

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.

coolmine
  • 4,427
  • 2
  • 33
  • 45
1

create custom control add ShowFocusCues and build to use

Example

public class button : System.Windows.Forms.Button
    {
        protected override bool ShowFocusCues
        {
            get
            {
                return false;
            }
        }
     }
0

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

Community
  • 1
  • 1
evgenyl
  • 7,837
  • 2
  • 27
  • 32
0

You can set the ShowFocusRectangle peoperty to false.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Ragul s
  • 21
  • 2
  • The [System.Windows.Forms.Button](https://learn.microsoft.com/de-de/dotnet/api/system.windows.forms.button?view=netframework-4.8) has no property called `ShowFocusRectangle`. I guess you are refering to the DEV Express button. – Martin Backasch Jun 21 '19 at 08:42
  • Yes I'm referring to the DevExpress simpleButton. – Ragul s Jun 21 '19 at 10:50
0

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
halfer
  • 19,824
  • 17
  • 99
  • 186
Nathan Evans
  • 139
  • 2
  • 3