473,441 Members | 2,080 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,441 software developers and data experts.

How Determine Which Control has Focus? #2

I am having the same problem as the one I found in google below:

http://groups.google.com/groups?hl=e...p02%26rnum%3D3

I need to determine which component has focus. When I select from the
main menu File->Save my validation is not called (the menu doesn't cause
the component to lose focus).

Unlike the above program, mine has over 40 controls in a single tab,
never mind the entire application. Is there an easier way than the
nightmare of each control setting an application-wide variable to say it
has focus?

--Liam.

Nov 15 '05 #1
2 28776
Liam,

You can import the GetFocus API method like this:

[DllImport("user32.dll")]
public static extern IntPtr GetFocus();

Once you have that, you can pass the result of that method to the static
FromHandle method on the Control class and it will return the Control
instance that is associated with that handle (assuming it is a .NET
control).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Liam McNamara" <ma**@newsgroup.net> wrote in message
news:3F**************@newsgroup.net...
I am having the same problem as the one I found in google below:

http://groups.google.com/groups?hl=e...p02%26rnum%3D3
I need to determine which component has focus. When I select from the
main menu File->Save my validation is not called (the menu doesn't cause
the component to lose focus).

Unlike the above program, mine has over 40 controls in a single tab,
never mind the entire application. Is there an easier way than the
nightmare of each control setting an application-wide variable to say it
has focus?

--Liam.

Nov 15 '05 #2
Thanks Nicholas, exactly what I was looking for.
Nicholas Paldino [.NET/C# MVP] wrote:
Liam,

You can import the GetFocus API method like this:

[DllImport("user32.dll")]
public static extern IntPtr GetFocus();

Once you have that, you can pass the result of that method to the static
FromHandle method on the Control class and it will return the Control
instance that is associated with that handle (assuming it is a .NET
control).

Hope this helps.


Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark Ingram | last post by:
Hi, ive just had to make a Find dialog for an application and to get it in a similar style to the MS ones i have had to set the control style to TopMost so that i can move the caret around...
6
by: Alex Bink | last post by:
Hi, I have a validating event on a textbox in which I want to prevent the user to leave the textbox without entering the right data. Only if he clicks on another specific control he is allowed...
3
by: Dzemo | last post by:
How to determine when user stop typing in text box (so that I can star with other process)? thx
1
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers for...
2
by: José Joye | last post by:
Hello, I need to determine which control has the focus in my page_load. Is there a way to do so. I have found lots of sample explaining how to set the focus (using javascript). but no info...
4
by: Jon Slaughter | last post by:
I've created some custom controls and forms that allow the feature to temporarily transfer focus to a control that has been entered by the mouse. Everything seems to work fine but the problem I...
10
by: John Brown | last post by:
Hi there, Does anyone know how to (generically) determine the currently active form for an application using a "static" function (so I can call it from anywhere). There is no offiical way I've...
0
nev
by: nev | last post by:
How can I determine the next control the user clicks on a certain control's validating event? For example, if I have textbox1 with the focus, and I click textbox2, how can I know from textbox1 that...
4
by: Bill Fuller | last post by:
I am trying to determine the type for ActiveControls using 3rd party controls (Infragistics in this case) during runtime and getting a rather odd return type at runtime for the UltraWinEditor. ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.