Events

  • Thread starter Thread starter exclaim
  • Start date Start date
E

exclaim

Can someone confirm that I have got the right idea about Events in VB.Net?

I know it is possible to set up custom events with custom eventarg
classes and use AddHandler to receive them - I have used this
successfully in the past. If I read the manuals correctly though, you
don't have to do this - simply declaring an object WithEvents, declaring
an event within the object code, raising the event within the object
code and making sure there is a Sub with the same signature in the
calling module which Handles the object's event is sufficient.

If this is so, why can't I get it to work? I can step through the
(successfully compiled) code and see the RaiseEvent line being executed,
but I never see the Handler sub entered.

Is there something else I need to do? Does anyone have a known working
example of a really simple event mechanism? All suggestions welcome...

Regards

--Jim.
 
exclaim said:
Can someone confirm that I have got the right idea about Events in
VB.Net?

I know it is possible to set up custom events with custom eventarg
classes and use AddHandler to receive them - I have used this
successfully in the past. If I read the manuals correctly though, you
don't have to do this - simply declaring an object WithEvents,
declaring
an event within the object code, raising the event within the object
code and making sure there is a Sub with the same signature in the

calling module which Handles the object's event is sufficient.

If this is so, why can't I get it to work? I can step through the
(successfully compiled) code and see the RaiseEvent line being
executed, but I never see the Handler sub entered.

Is there something else I need to do? Does anyone have a known
working example of a really simple event mechanism? All suggestions
welcome...


Did you add the 'Handles' keyword to the event handler?

sub bla(...) handles myvar.eventname


Armin
 
Explain,

Declaring withEvents gives you the possibility to use the inbuild Event
handling/setting from VBNet. This is an extra from VBNet. You are not oblied
to use this. However, it is so handy that you would be a fool when you did
not.

You can forever use all standard Net Procedures as long as it is Managed
code with VBNet. Therefore the AddHandler method works as well just beside
it and can be used where the withEvents does not work. By instance by
threading or recursive use.

I hope that this gives an answer.

Cor
 
Armin

I am glad to see you write an answer, Yesterday I was thinking has Armin
already seen enough of this newsgroup again.

:-)

Cor
 

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

Back
Top