Catch Enter-key when focus on a button
-
I have some strange problem here, so i was wondering if i could solve it in this way (i know it's not the best way to solve a problem, but i want a quick and dirty solution at the moment) Let's say i have a button, with the focus on it. When i press the button a messagebox is shown. I only want the messagebox to be shown when i press the button with my mouse. When i press enter i don't want the messagebox to be shown. So i tried handling the keypress method and set the eventargs e.handled=true. But no effect, it doesn't even get inside the keypress method when pressing enter... I know it's a strange question, but anyone have any ideas? Thanks in advance.
-
I have some strange problem here, so i was wondering if i could solve it in this way (i know it's not the best way to solve a problem, but i want a quick and dirty solution at the moment) Let's say i have a button, with the focus on it. When i press the button a messagebox is shown. I only want the messagebox to be shown when i press the button with my mouse. When i press enter i don't want the messagebox to be shown. So i tried handling the keypress method and set the eventargs e.handled=true. But no effect, it doesn't even get inside the keypress method when pressing enter... I know it's a strange question, but anyone have any ideas? Thanks in advance.
-
I have some strange problem here, so i was wondering if i could solve it in this way (i know it's not the best way to solve a problem, but i want a quick and dirty solution at the moment) Let's say i have a button, with the focus on it. When i press the button a messagebox is shown. I only want the messagebox to be shown when i press the button with my mouse. When i press enter i don't want the messagebox to be shown. So i tried handling the keypress method and set the eventargs e.handled=true. But no effect, it doesn't even get inside the keypress method when pressing enter... I know it's a strange question, but anyone have any ideas? Thanks in advance.
Hello! I am quite new to programming. I have no ideea how to cancel these 'automatic' key events that rise from hiting 'enter' or 'space' on a button but here is how i would do it: Set button's 'TabStop' to false. Create an 'enter' event and put this inside the event:
SelectNextControl(yourbuttoncontrolhere, true, true, true, true);
This won't allow the user to focus the control in any way but it will allow him to click the button. Hope this helps, Good luck! -
I have some strange problem here, so i was wondering if i could solve it in this way (i know it's not the best way to solve a problem, but i want a quick and dirty solution at the moment) Let's say i have a button, with the focus on it. When i press the button a messagebox is shown. I only want the messagebox to be shown when i press the button with my mouse. When i press enter i don't want the messagebox to be shown. So i tried handling the keypress method and set the eventargs e.handled=true. But no effect, it doesn't even get inside the keypress method when pressing enter... I know it's a strange question, but anyone have any ideas? Thanks in advance.
I dont understand why you fired button1_Click event....just fired button1_MouseClick event that's it..
Thanks Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.