473,386 Members | 1,817 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,386 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 28768
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. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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,...

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.