0

As picture shows:

https://drive.google.com/file/d/0B4XV2HrbrpDZX0xnZ1o1SHhiWm8/view?usp=drivesdk

I would like to remove the highlight after each click because I have set acceptbutton and ActiveControl to the "equal" button of this program I want the operation of AcceptButton takes place instead of input the highlighted button text when I key press Enter on keyboard. Any idea? Thanks.

K. Furkan BEK
  • 233
  • 1
  • 2
  • 9
user6670219
  • 11
  • 1
  • 1
  • Code so far? SO is not a code writing service. – techydesigner Aug 03 '16 at 02:21
  • @techydesigner what the code you means? I created this program, just want to know any method to remove the highlight – user6670219 Aug 03 '16 at 02:26
  • Surely there is something in the code that would affect it. It could be a glitch, but at least some of the code specific to the button could be helpful to other users. – techydesigner Aug 03 '16 at 02:34
  • 1
    @techydesigner By the question "Any idea?" I would guess that the `OP` is asking for ideas and not code writing as a service. The question does not require code in any way to be clear. – Leandro Aug 03 '16 at 02:35
  • @LeandroTaset There may be something in the code affecting this. Either way, I don't know C# specifically so I will leave it to the experts. – techydesigner Aug 03 '16 at 02:36
  • @user6670219 You would have to play with all things that affect focus for a control. These are all good starting points: [Control.ShowFocusCues property](https://msdn.microsoft.com/en-us/library/system.windows.forms.control.showfocuscues.aspx), [Control.Focus() method](https://msdn.microsoft.com/en-us/library/system.windows.forms.control.focus.aspx) and [Control.SetStyle() method](https://msdn.microsoft.com/en-us/library/system.windows.forms.control.setstyle.aspx). – Leandro Aug 03 '16 at 02:42
  • 1
    Create a custom button deriving from `Button` and make it non-selectable in constructor: `this.SetStyle(ControlStyles.Selectable, false);` Like [this post](http://stackoverflow.com/a/10078372/3110834) – Reza Aghaei Aug 03 '16 at 05:45

3 Answers3

0

I think this question is duplicate of How do I prevent WPF buttons from remaining highlighted after being clicked?


Here is the solution:

What happens is that the button accepts the input focus after it has been clicked, just like any other control does when you click on it.

And the way that Windows indicates that a control has the input focus (at least under the Aero theme) is with a subtle blue highlight.

For a button control in particular, when it has the input focus, simply pressing the Enter key will "push" that button. That's why maintaining the highlight is very important, so that the user knows what to expect.

The better solution is to set the focus to a different control in your window immediately after the user has clicked on the button. That way, it will no longer be automatically highlighted and no action will be automatically triggered when the user presses the Enter key. (This is the real usability problem that you're trying to solve, even if you don't know it yet. Nothing is more confusing than a button inadvertently getting clicked when the user is actually trying to type something.)

You could prevent the button from ever getting the focus altogether by setting its Focusable property to false, but I would very much recommend against this. Once you've done this, there will be no way for the user to "press" the button using only the keyboard. Well-designed applications should always be accessible to users who either prefer not to or who are unable to use the mouse.

Community
  • 1
  • 1
K. Furkan BEK
  • 233
  • 1
  • 2
  • 9
0

Given that you "want the operation of AcceptButton takes place instead of input the highlighted button text when I key press Enter on keyboard.", one solution is to have the click handler for each button give focus to =.

Google "winforms control set focus" for code details.

This would preserve accessibility: keyboard-only users can Tab to the desired button, press Enter to "click" the button. Your click handler would then give focus to =, so it will be clear that another Enter would perform = action.

It also makes it clear to any user that they can press Enter at any time, to get =.

On the other hand, it might be "disconcerting" to users to constantly see = get highlighted. Would require user-testing...

ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196
0

You can change the buttons to flat:

btn.FlatStyle = FlatStyle.Flat;

and then change the FlatAppearance:

btn.FlatAppearance.MouseDownBackColor = Color.Transparent;
btn.FlatAppearance.MouseOverBackColor = Color.Transparent;
Hellboy.
  • 63
  • 7