By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,098 Members | 1,881 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,098 IT Pros & Developers. It's quick & easy.

tab key, mouse click, or select method

P: n/a
In the enter event of a combo box, how to know how this control got the
focus :
- by clicking on it with the mouse
- with the tab key
- with the Select method of the control class
I will want to do an action only if the combo box received focus after a
tab key press.

Thanks
Fred
(France -imperfect english)
Nov 4 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Set the Form's KeyPreview property to true, and override the OnKeyDown
method. Create a Form-level boolean variable and if it is a Tab Key, set the
variable to true. Otherwise set the variable to false. Also handle the
MouseDown event for the combo box, and set the variable to false there. Then
the Focus event handler for the combo box can check the variable to find out
if the Tab key was just pressed, or if it was entered via a Mouse Click or
some other Key event.

--
HTH,

Kevin Spencer
Microsoft MVP
Ministry of Software Development
http://unclechutney.blogspot.com

I just flew in from Chicago with
a man with a wooden leg named Smith
who shot an elephant in my pajamas.
So I bit him.
"Fred" <fb_x_ng@fr_x_ee.frwrote in message
news:45**********************@news.free.fr...
In the enter event of a combo box, how to know how this control got the
focus :
- by clicking on it with the mouse
- with the tab key
- with the Select method of the control class
I will want to do an action only if the combo box received focus after a
tab key press.

Thanks
Fred
(France -imperfect english)

Nov 4 '06 #2

P: n/a
Hi Fred,
I will want to do an action only if the combo box received focus after a
tab key press.
You can use the solution that Kevin has given. However, I started to think
your application and the requirement you have, as to me it fights against
the normal Windows user interface conventions.

What kind of activity would you want to do when the user presses the Tab key
to move to another control instead of using for example the mouse? How about
the Alt hotkeys that you can assign to a label control?

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi
http://www.saunalahti.fi/janij/
Nov 5 '06 #3

P: n/a
Hi,

First : thanks for responses.
I have a form with a lot of input fields (text and combo boxes). I want
that filling these fields be easy and quick for user. So if it navigates
through controls with the tab key, when he arrives on a combo box, i
want to automatically open the combo box. For this I created a handler
for the Enter event, as it :
private void cb_Enter(object sender, EventArgs e)
{
ComboBox cb = (ComboBox)sender;
if (cb.SelectionIndex == -1) cb.DroppedDown = true;
}
This works fine when the user uses the tab key; but when he clicks with
the mouse, then the combo box is opened and closed immediatly : I will
want to prevent this.

Fred
Jani Järvinen [MVP] wrote:
Hi Fred,

>>I will want to do an action only if the combo box received focus after a
tab key press.


You can use the solution that Kevin has given. However, I started to think
your application and the requirement you have, as to me it fights against
the normal Windows user interface conventions.

What kind of activity would you want to do when the user presses the Tab key
to move to another control instead of using for example the mouse? How about
the Alt hotkeys that you can assign to a label control?
Nov 5 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.