External control events

dmdb

New member
Joined
Jan 2, 2008
Messages
2
Location
London, UK
Programming Experience
1-3
Hi all,

I'm having problems with an external activex control which I'm using for an application I've been asked to try and make work by my boss, this bit is going beyond my experience and google hasnt helped as much as it usually does!

I have an external control as mentioned which is dynamically created on the form at runtime as a variable number of them need to be running. The settings for each are read from an xml config file, thats fine and I can create them and they do what they're expected to do.

The problem is dealing with events from these controls, simple things such as mouse clicks and other custom events which the control has. I don't know how to create a function to handle these events, so for instance how I might (for arguments sake) fetch one of the controls tag when the mouse is clicked on on it.

In theory I know I can when the controls are created use AddHandler to do this but I constantly get errors saying that the signatures don't match which I can't get rid of.

I hope I've provided enough information, I've been using a dumbed down project (sans xml config and the rest of the app) just to try and build a working version first of all and am using the below to load the controls at the moment:

VB.NET:
For i As Integer = 0 To 5
Dim src As New acti.AxnvUnifiedControllib
src.Location = New Drawing.Point(8, 150 + i * 24)
src.TabIndex = i
src.Text = i.ToString
src.Tag = i.ToString
AddHandler src.Click, AddressOf srcClick
Controls.Add(src)
Next

And then the below to try and fetch that click which doesnt work:

VB.NET:
Private Sub srcClick(ByVal sender As Object, _
ByVal e As EventArgs)
MessageBox.Show("Clicked was " & _
DirectCast(sender, acti.AxnvUnifiedControllib).Tag.ToString)
End Sub

Hoping someone can give me some pointers for dealing with external controls as I've hit a real road block and would appreciate anything anyone can offer...

Many thanks,

DB
 
If the signatures don't match then you have to change the signature of your method so it does match. The event in question must not pass an EventArgs object to its handlers. It must pass something else, so you need to declare the second parameter as that type.

The easiest way to do this is to actually add an instance of the control to your form in the designer and let the IDE create the desired event handlers for you. You can then delete the control from the form and the event handlers will be left behind, all with the appropriate signature for the event you want to handle.
 
jmcilhinney Thank you, it took me a little while to make it work but it is now, I've been slowly gleaning other little bits for other parts of the app from other threads as well so hopefully I should be able to progress now.

Thanks very much!
 
Back
Top