Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2002

    Unanswered: Passing Argument To Public Event Handler

    How to pass a default argument to the public event handler?
    Event handler for mouse move will have Button, Shift, X, and Y... How to get this value if the event handler is on the module. I want to assign this handler programmatically from the vb code, therefore I use something like: ctlControl.OnMouseMove = "=myMoveHandler()"

    If I define the args of myMoveHandler as follows
    (Button As Integer, Shift As Integer, X As Single, Y As Single),
    how can I pass these values from the OnMouseMove property of every controls in my form?

  2. #2
    Join Date
    Aug 2002
    Québec, Canada
    Yoops, I don't think you can't, you'll have to use the default OnMouseMove, and then, in the OnMouseMove event (of all control), call the MyMoveHandler with the proper argument...


  3. #3
    Join Date
    Oct 2002

    Re: Passing Argument To Public Event Handler

    Have you tried using WithEvents?

    You could define a Class Module clsMoveHandler which does this for you:

    Private WithEvents mctlControl As Control
    Public Property Set Control(ctlControl As Control)
       Set mctlControl = ctlControl
       mctlControl.OnMouseMove = "[Event Procedure]"
    End Property
    Private Sub ctlControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
       'Your Event Handler Here
       Debug.Print ctlControl.Name & ".clsMoveHandler.MouseMove"
    End Sub
    You can then specify this handler for each control you want to use it for:

    in Form
    Private mhndlrControl1 As clsMoveHandler
    Private Sub Form_Open()
       Set mhndlrControl1 = New clsMoveHandler
       Set mhndlrControl1.Control = ctlControl1
    End Sub
    When the mouse moves over ctlControl1 your event handler is called.

    If you want to do this for multiple controls you'll probably want to define an array or Collection of clsMoveHandler and add each Control to it one at a time...

Posting Permissions

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