Is it possible that its just a keyword for the visual basic compiler that
connects an object's events to some handlers? C# and Visual Basic both
compile to IL, if it did have overhead (other than compilation) it would
have to show up there.
I am pondering here but would imagine that there is no overhead because I
would again imagine that the MSIL compiler is very efficient and would
realize that there are no eventsinks for the object and hence remove and
event handling code.
A question for you is why would you declare an object withEvents if you do
not plan on using them?
You are correct, WithEvents (in conjuction with the Handles clause) removes
the arduous task of AddHandler and RemoveHandler on all events for any
controls you make.
--
HTH,
-- Tom Spink, Über Geek
Please respond to the newsgroup,
so all can benefit
" System.Reflection Master "
==== Converting to 2002 ====
Remove inline declarations
As it's already been mentioned, Withevents does Addhandler/removehandler
internally for you.
Variables declared with Withevents are actually properties.
Writing
private withevents cmd as button
sub cmd_click(...) handles cmd.Click
end sub
is exactly the same as
private _cmd as button
private property cmd() as button
get
return _cmd
end get
set (byval value as button)
if not _cmd is nothing then
removehandler _cmd.click, addressof cmd_click
end if
_cmd = value
if not _cmd is nothing then
addhandler _cmd.click, addressof cmd_click
end if
end set
end property
The more "Handles" procedures, the more removehandler/addhandler statements
are created.
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.