Adding key events to a label

  • Thread starter Thread starter Edgardo Rossetto
  • Start date Start date
E

Edgardo Rossetto

Is it possible? How can I do it?

I read the documentation about the events and delegates, but its somehow
unclear, specially since it doesn't involve any data, I only want to add
the key events to the label control.

Sorry if this is dumb, I'm kind of newbie.
 
The simplest way to create the code to handle a label event is to drop one
on a form and double-click it. VS will create the code to add the
EventHandler and stub out the procedure for you. By default, you'll get
code to handle the Click event. To see the other events that are available
for a Label, type

this.label1.

Assuming the label you added to your form is called label1, typing that last
'.' should drop down the IntelliSense list. From this list, you can see all
the events (the ones in the list with the "lightning bolts") that are
available for labels. Not all events are available for all controls. There
won't be any Key events for labels since you can't type into them.

Other ways to view available events are in the Object Browser and in the
Properties Window by clicking on the Events button.

Perhaps if you explained what you wanted to respond to with your labels,
someone could offer a good suggestion.
 
Yes, I tried that, but by default the key events are not in the label
control, my question is how can I add that event by hand.
 
If a label control doesn't do the job, perhaps you should consider using a
TextBox control and adjusting it's properties to make it look like a Label
(e.g., BorderStyle, BackColor, etc). You would have to mess with the
properties a bit, but you would get the Key events. You would also have to
ensure the text didn't change. It sounds like a Label control may not work
for you. Labels just don't get the input cursor, so they don't get Key
events.

Earl Damron
 
Back
Top