AddHandler

robM
12-04-2004, 09:56 PM
Hey,

In my program, I declare the variable lapt as follows:


Public lapt


Later in the code, based on some other factors, I set the lapt variable to represents a control in a code such as


lapt = New Label()


Then I try to add a handler to the new object:

AddHandler lapt.Click, AddressOf lapt_Click


The intellisence fusses over the lapt.click, saying:
"click is not an event of system.object"

How can i solve this issue?

robM

Joe Mamma
12-04-2004, 10:36 PM
Public lapt as Control

excaliber
12-05-2004, 06:37 AM
Agreed, do what Joe Mamma is saying.

But, if you have a really odd instance where the variable could also be other things other than a control (not ever recommended, typing your variables is a good thing), you could DirectCast it:


AddHandler DirectCast(lapt, Button).Click, AddressOf lapt_Click
'
AddHandler DirectCast(lapt, Control).Click, AddressOf lapt_Click
'
'Etc Etc

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum