Setting Event Code at Runtime

D

dchman

I have a form which is populated with various controls at runtime. I also
want to populate the "OnMouseDown" event.

If I set the event procedure at design time it would look like this;

Private Sub CMD1_MouseDown(Button As Integer, Shift As Integer, X As Single,
Y As Single)
Call SetCurCtrl(Screen.ActiveControl)
End Sub

I think it is possible to set the OnMouseDown event at runtime, but I
haven't been able to figure out the syntax for the above example (I want to
send a reference for the control to another procedure).

Any ideas?

thanks
 
K

Klatuu

Since you know which control you are in, the Screen.ActiveControl is not
really necessary. You could just use Me.CMD1. Now, the trick is you are
sending an object reference, not a text reference. So the Sub you are
calling needs to type the argument as a control.

Sub SetCurCtrl(ctlSomeControl as Control)

To send it the name of the control as text it would be called as:

Call SetCurCtrl(Me.CMD1.Name) and the Sub would be
Sub SetCurCtrl(strSomeControl as String)
 

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