Need help defining an event handler...

S

SpreadTooThin

I'm running Visual Basic Express Editon 2008.
I have a project that references an OLE object called MyObject
That object fires events.
How do I declare the event handler in the Main Form class
implementation?

Public Class Form1

Dim WithEvents server as MyObject.MyServer

? How do I declare the event handler?

End Class

I was told that it should be in the IDE but I don't see anything that
would help me declare this method in my code.
 
K

kimiraikkonen

I'm running Visual Basic Express Editon 2008.
I have a project that references an OLE object called MyObject
That object fires events.
How do I declare the event handler in the Main Form class
implementation?

Public Class Form1

   Dim WithEvents server as MyObject.MyServer

?  How do I declare the event handler?

End Class

I was told that it should be in the IDE but I don't see anything that
would help me declare this method in my code.

As you're using a form, you can also subscribe its events in your
Form1.Designer.vb partial class like:
Friend WithEvents server As MyObject.MyServer

To handle, use Handles clause:
Like that:


Public Class Form1

' In your form
' Assuming it has a click method
Private Sub MyServer_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyServer.Click

End Class


....of course i cannot test it as the object is custom (not included in
framework, thus we don't know what events and signatures it expose),
but hope that gives some idea.

Hope this helps,

Onur Güzel
 
L

Lloyd Sheen

SpreadTooThin said:
I'm running Visual Basic Express Editon 2008.
I have a project that references an OLE object called MyObject
That object fires events.
How do I declare the event handler in the Main Form class
implementation?

Public Class Form1

Dim WithEvents server as MyObject.MyServer

? How do I declare the event handler?

End Class

I was told that it should be in the IDE but I don't see anything that
would help me declare this method in my code.


Ok:

1. Open form with the OLE object in the designer
2. Select the object on the form
3. Go to properties (F4)
4. In the properties window click the lightning bolt at on the properties
window toolbar
5. You should now see a list of all the events which the dot.net
framework knows about for the object
6. Double click in the dropdown box to the right of the Event name

This should create a stub for you in your code.

LS
 
L

Lloyd Sheen

John Whitworth said:
But that just handles simple, built-in events. I think that the OP wanted
a custom event that could be picked up by other forms/objects.

JW

An event is an event. There are no custom events just events. If an object
on a form has PUBLIC events they will show in the list unless there is an
attribute (don't know what it is offhand) that will stop the event from
showing in the list.

The OLE object dropped on the form has to be of a type that exposes the
event.

LS
 
S

SpreadTooThin

An event is an event.  There are no custom events just events.  If anobject
on a form has PUBLIC events they will show in the list unless there is an
attribute (don't know what it is offhand) that will stop the event from
showing in the list.

The OLE object dropped on the form has to be of a type that exposes the
event.

LS

It was all so easy before... Why so difficult now.
Maybe because I didn't put the object on the form.
 

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