Attaching an event handler

W

Water Cooler v2

I am creating a LinkLabel control at runtime. How do I attach an event
handler to it?

Where's the delegate for the OnClick event? I see an OnLinkClicked
delegate but since it is protected, it won't let me set it to the
address of my own handler.

Do I have to inherit every control just because I want to create it
dynamically at runtime?

Bottomline: If I've created a control at runtime, how do I attach my
own event handler to it. I mean, I know the syntax but I see that the
delegates are all "protected."
 
H

Herfried K. Wagner [MVP]

Water Cooler v2 said:
I am creating a LinkLabel control at runtime. How do I attach an event
handler to it?

Take a look at the 'AddHandler' statement.
 
W

Water Cooler v2

ok, how out of curiosity. If this was C# I was coding in, there's no
AddHandler there, so I believe the only way to do it would be to pass
the name (which is actually the address) of my own handler to the
delegate instancen member inside the control class. Since all these
delegate instance members are protected, would there have been a way to
do it in C# that did not involve inheriting from the control?
 
H

Herfried K. Wagner [MVP]

Water Cooler v2 said:
ok, how out of curiosity. If this was C# I was coding in, there's no
AddHandler there, so I believe the only way to do it would be to pass
the name (which is actually the address) of my own handler to the
delegate instancen member inside the control class. Since all these
delegate instance members are protected, would there have been a way to
do it in C# that did not involve inheriting from the control?

You don't need to inherit in order to be able to add a handler.

\\\
this.Button1.Click += new System.EventHandler(this.Button1_Click);
///
 
C

Chris Dunaway

Water said:
I am creating a LinkLabel control at runtime. How do I attach an event
handler to it?

Use the AddHandler statement

Where's the delegate for the OnClick event? I see an OnLinkClicked
delegate but since it is protected, it won't let me set it to the
address of my own handler.

If you are creating the control at runtime, you need to attach to the
LinkClicked event, not OnLinkClicked.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top