Clickable Label revisited

  • Thread starter Thread starter William Ryan
  • Start date Start date
W

William Ryan

I'm familiar with the label examples and understand them.

Here's what I don't understand though....if I drag a label onto a form and
add this event handler, it's kosher
this.label1.Click += new System.EventHandler(this.label1_Click);

Now, if I add a hanlder for label1_click like so:

private void label1_Click(object sender, System.EventArgs e)

{MessageBox.Show("It Worked");}

And I click on the label, nothing happens. however, the event does show up
in this.label1. and I thought all controls had click as an event.

If I do the EXACT same thign with a PictureBox, it works fine. When I click
on the label nothing, click on the pictureBox works as expected.

I don't need to use a clickable label at the moment, but I'm wondering why
this behavior is what it is?

TIA,



Bill
 
The click event is not supported for labels.
THis is allowed but is an oversight by MS or they plan to
implement this in the future. Currently you cannot get
click notification for a label.

Write your own.

Garth
 
I know that it doesn't work, I'm just wondering why b/c it's a method of
click and the PictureBox for instance can do it effectively.

The fact that they left it in and is an oversight though explains it.

Thanks,

Bill
 
If you create an inherited control from label object you can code for it
- I've seen it done, teefed it and used it myself... clickable labels..
 
It doesn't do anything because the Label doesn't implement a click event.
It inherits from Control, so the event shows up, but under the hood, it
never raises the event.
 
Back
Top