473,402 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

tab key, mouse click, or select method

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
3 2565
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Dann | last post by:
This question has arisen from an earlier thread but is really a separate issue: I have a VB.Net listbox control on a form. I want to be able to do 2 things with items displayed within the one...
5
by: Nick | last post by:
Hey guys, I have 2 events on a windows forms datagrid, the mouse move as well as the double click events. What's happening is that when I double click on a row in the grid, the mouse move event...
0
by: mmcd79 | last post by:
I'm wondering if anyone else is having this issue. It's driving me batty. It seems my mouse wants to "double click" on items when I'm just doing a single click. I thought it was the mouse so I...
3
by: Morten Snedker | last post by:
If I have a number of random applications open, move the mouse cursor to a given position and do a click, the application gets the focus. That is what this simple code should illustrate: Dim...
5
by: Adeel | last post by:
Hi group! I'm trying to learn C# on my own... I'd appreciate it very much if someone can help me out here. I have a basic form without any controls on it... I want to catch mouse clicks (both...
5
by: moonie | last post by:
I have an msn style c# windows application with a form and panel on it. A news list is drawn from the database and dynamically added via labels, link lables during form loading. In this...
5
kadghar
by: kadghar | last post by:
Most of the times VBA is used with variables. Objects (such as worksheets, cells or databases) are only used when we read their properties (value, formula, font...) or we use a method (save,...
7
by: Barkingmadscot | last post by:
I am try to find out how to check if the mouse button is held down. The e.click =2 works, it allows me to enter the double click double. I what the single click to do some different and then...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.