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 HobbsPosted Mar 9, 2010, 7:21 PM
Sam HobbsPosted Mar 9, 2010, 8:31 PM
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.
GustavoPosted Mar 9, 2010, 7:55 PM
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 HobbsPosted Mar 9, 2010, 7:52 PM
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?
GustavoPosted Mar 9, 2010, 7:42 PM
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?
GustavoPosted Mar 9, 2010, 6:30 PM
Nope, I dont. Is it simple to learn?
Sam HobbsPosted Mar 9, 2010, 6:28 PM
GustavoPosted Mar 9, 2010, 5:14 PM
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 HobbsPosted Mar 9, 2010, 4:58 PM
GustavoPosted Mar 9, 2010, 8:49 AM
I will try it out. Not sure where to actually put it. But It will give me something to play with.
Sam HobbsPosted Mar 9, 2010, 3:36 AM
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.
Hirendra SisodiyaPosted Mar 8, 2010, 11:39 PM
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