RaiseEvent in DOT .NET so that VB6 can respond

J

JeffR

I created a user control in VB .NET and put a COM wrapper around the
control so that a VB6 client could dynamically add the control to a
form. The only thing I haven't figured out is if the VB .NET user
control can raiseevent and have the VB6 container respond to that
event.


I've tried the following:

<ComClass(UserControl1.ClassId, UserControl1.InterfaceId,
UserControl1.EventsId)> _
Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Public Event TestEvent()

....
...

#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String =
"CF573EBC-804F-4086-A08F-2239E56BADFE"
Public Const InterfaceId As String =
"D9F75135-7D89-44FE-AA2C-21E742A187FB"
Public Const EventsId As String =
"E8FECC77-2988-4C29-9A7B-04F9ED2909BA"
#End Region

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
RaiseEvent TestEvent()
End Sub

Friend WithEvents Button1 As System.Windows.Forms.Button
end class

------------------

Now in the VB6 app I've done the following:

Option Explicit

Private oMyControl As New TestControl.UserControl1
Private WithEvents theEvent As TestControl.UserControl1

Private oUserControl As Object

Private Sub Form_Load()


Set oUserControl = Controls.Add("TestControl.UserControl1",
"doesntmatter")
oUserControl.Left = 0
oUserControl.Top = 0
oUserControl.ZOrder 0
oUserControl.Visible = True

Set theEvent = oMyControl


End Sub

Private Sub theEvent_TestEvent()
MsgBox "this is the vb 6.0 event"
End Sub

I never get to the VB 6.0 event handler when I click the button inside
the DOT Net control


Anyone have any ideas?

Thanks!

Jeff
 
J

Jeffrey Reese

Oops.. a bit redundant.

I really meant .NET or DOT NET. Do you have any ideas on my issue?
 
C

CJ Taylor

It should work just fine using RaiseEvent... I don't see any reason why it
wouldn't, events are supported through the interop.

-cJ
 

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

Similar Threads


Top