How can I add an onclick event to a control that does not have it?
Printable View
How can I add an onclick event to a control that does not have it?
Open the ocx or dll, and after finding the right control add under the option explicit statement:
Event Click()
then when you want the event to occur, RaiseEvent. eg.
Hope it works :)Code:Private Sub UserControl_Click()
RaiseEvent Click()
End sub
I dont have the source code for the control..
The easiest thing I can think of would be to build another control. You can simply drop in the control you are trying to change, use the ActiveX interface wizard to pass through all the properties, methods and events from the existing control, then add your own click event. You can use the code above to do that...
Since you didn't reply, I am guessing that you are still having trouble with it.
Follow these steps:
1.)Open VB
2.)On the Wizard select Active X Control
3.)Once loaded press Ctrl + T
4.)Select the control you wish to alter
5.)Once the control is loaded drag it from the controls menu to the user control
6.)Go to code section
7.) Add folowing code.
As simple as that. You might not need all the code included, depending on the control.Code:Option explicit
Event Click()
Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Private Sub Usercontrol_Initialize()
Usercontrol.Width = ModifyingControl.Width
Usercontrol.Height = ModifyingControl.Height
End Sub
Private Sub Usercontrol_Click()
RaiseEvent Click()
End Sub
Private Sub Usercontrol_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
End Sub
Private sub Usercontrol_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
End Sub
Private Sub ModifyingControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
End Sub
Private sub ModifyingControl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
End Sub
If it doesn't work, just reply saying what it has a problem with.