-
January 29th, 2011, 08:57 PM
#1
How does WinForms label control handle focus? (a newbie question, perhaps)
Folks,
There is a panel which contains 2 components: a label and a TreeView. The hierarchy, obviously, looks like this:
Code:
panel1 // handles Enter event
- label1
- treeView1
I need to do some UI updates when user starts interacting with any of these 3 controls. My attempted strategy was to catch the Enter event of the panel, which would fire when user clicks a label, or TreeView. This way, I can write only one (1) event handler instead of several. While it worked for the TreeView, it didn't work for the label. When I click the label, I don't get the Enter event on the panel. What’s different about the label control?
I could handle the Click event of the label. At the same time, I wonder what the other solutions might be.
Any suggestion, insight or reference is really appreciated!
- Nick
-
January 30th, 2011, 07:37 PM
#2
Re: How does WinForms label control handle focus? (a newbie question, perhaps)
Hello Kender.
Similar to the suggestion offered in thread "Dynamic test for lable (in form)"
the following suggestion seems to be working here on my machine where I have a panel containing a label and a treeview as you describe.
In this particular case, clicking on either the label or the treeview places the appropriate control name ('label1' or 'treeView1') in the associated text box, demonstrating that both controls are serviced by the common handler, and that the handler is able to distinguish between the two controls.
Code:
// ****************************************************
// common label:Click / treeView:MouseUp handler
// ****************************************************
private void panel_Click(object sender, EventArgs e) {
if (sender.GetType().Equals(label1.GetType()))
textBox1.Text = ((Label)sender).Text;
else
textBox1.Text = ((TreeView)sender).Name;
}// end common-object handler
the trick is that, in this particular case, the label event is 'Click' whereas the treeView event is 'MouseUp'
Last edited by ThermoSight; January 30th, 2011 at 08:53 PM.
-
January 30th, 2011, 09:43 PM
#3
Re: How does WinForms label control handle focus? (a newbie question, perhaps)
Originally Posted by kender_a
What’s different about the label control?
It's read-only so the user doesn't interact with it.
Can you be more specific with regard to "do some ui updates"? Can you describe what you are trying to do in more detail?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|