Hello:
Is there a service/control/whatever that can be running in a program and let me know what is focused?
Reason is: I would like to have something running that can update the statusBar with what is Focused. I know I can put code for each object on Enter and on Leave. But I have many objects and I hate to put so much redundant code in the program. Also I would like to write a routine that validates the field that is just left and go to the validation routine and if invalid go back to the field. Am I dreaming, too much?
Loading

Sam HobbsRank #107 · 20.5K reputationPosted Mar 9, 2010, 2:21 PM EST
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Mar 8, 2010, 6:39 PM EST
foreach (Windows.Forms.Control obj in this.Controls) {
if (obj.Focused) {
}
//obj is focused
}
if you want to know another thing,let me know
thanks
Sam HobbsRank #107 · 20.5K reputationPosted Mar 8, 2010, 10:36 PM EST
Control c = GetNextControl(null, true); while (c != null) { c = GetNextControl(c, true); }Another option is to use an Application.Idle Event for the form and in the event use the ActiveControl property. That might not work if there are multiple forms, unless you include code to deal with that. I think if you add an idle event handler for a form, it will be executed for all forms so that might be too advanced for you if you are not familiar with Windows enough.
GustavoRank #1,990 · 732 reputationPosted Mar 9, 2010, 3:49 AM EST
I will try it out. Not sure where to actually put it. But It will give me something to play with.
Sam HobbsRank #107 · 20.5K reputationPosted Mar 9, 2010, 11:58 AM EST
GustavoRank #1,990 · 732 reputationPosted Mar 9, 2010, 12:14 PM EST
I put it where you wanted me to... but How do I use it?
I wanted the value of what is focused to go to:
toolStripStatusLabelHint.Text = _______;
Sam HobbsRank #107 · 20.5K reputationPosted Mar 9, 2010, 1:28 PM EST
GustavoRank #1,990 · 732 reputationPosted Mar 9, 2010, 1:30 PM EST
Nope, I dont. Is it simple to learn?
GustavoRank #1,990 · 732 reputationPosted Mar 9, 2010, 2:42 PM EST
Thanks... Now I see how it works...It cooool.
It shows: System.Windows.Forms.textBox, Text:
Is there a way I can get back the name of the text box?
Sam HobbsRank #107 · 20.5K reputationPosted Mar 9, 2010, 2:52 PM EST
Perhaps you are saying that because that is what you are putting out in your code. To see what else you can put out, just look at the members of the Control class or whatever the relevant class is. Did you try that?
GustavoRank #1,990 · 732 reputationPosted Mar 9, 2010, 2:55 PM EST
For testing I took out the: if (c.GetType().Name == "TextBox"). So it would tell me what all of 'c' is.
I will surf and try to find more info on it, to see what else I can pull out of it. Thanks
Sam HobbsRank #107 · 20.5K reputationPosted Mar 9, 2010, 3:31 PM EST
Just look at the Control class; I think the Name property is what you are looking for. But maybe it is not; you probably want the label, not the name, and that is not as easy. What I might do is to use the Tag property, as in textbox1.Tag. I would set it to the label control that has the field title in, so I could get the value dynamically. Try to figure that out on your own.