Results 1 to 5 of 5

Thread: Adding new events 2 a control!!! ASAP!!!!!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    70

    Exclamation

    How can I add an onclick event to a control that does not have it?
    Kiziltan Yuceil
    Freelance Web/VB/VBA Programmer
    "It's not what you know it's to whom you consult and with whom you collaborate"

  2. #2
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    I think I have posted to this before, but I am not sure.

    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.

    Code:
    Private Sub UserControl_Click()
           RaiseEvent Click()
    End sub
    Hope it works
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    70

    Yes but..

    I dont have the source code for the control..
    Kiziltan Yuceil
    Freelance Web/VB/VBA Programmer
    "It's not what you know it's to whom you consult and with whom you collaborate"

  4. #4
    Hyperactive Member Scott Penner's Avatar
    Join Date
    Dec 2000
    Location
    Mountain View
    Posts
    327

    Lightbulb make another 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...
    -scott
    he he he

  5. #5
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    Use Scott's Idea

    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.

    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
    As simple as that. You might not need all the code included, depending on the control.

    If it doesn't work, just reply saying what it has a problem with.
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width