[VB.NET] Handling events from a module

Discussion in 'Mixed Languages' started by stevemk14ebr, May 4, 2013.

  1. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    #1 stevemk14ebr, May 4, 2013
    Last edited by a moderator: Apr 20, 2017
    i have a few events that are called from a mouse hook, i use raise events from a module to well raise the events i then ATTEMPT to use this code to handle the event back in form1.vb:
    Code:
     Private Sub mHook_Mouse_Left_DoubleClick(ByVal ptLocat As System.Drawing.Point) Handles MouseHook.Mouse_Left_DoubleClick
            Debug.WriteLine("Mouse Left Double Click At: (" & ptLocat.X & "," & ptLocat.Y & ")")
        End Sub
    Code:
    'constants taken out for simplicity i'm only showing the events
    
     Public Event Mouse_Move()
        Public Event Mouse_Left_Down()
        Public Event Mouse_Left_Up()
        Public Event Mouse_Left_DoubleClick()
        Public Event Mouse_Right_Down()
        Public Event Mouse_Right_Up()
        Public Event Mouse_Right_DoubleClick()
        Public Event Mouse_Middle_Down()
        Public Event Mouse_Middle_Up()
        Public Event Mouse_Middle_DoubleClick()
        Public Event Mouse_Wheel()
    
    'stuff you don't care about taken out later in the program is this below to raise events
    
       If (nCode = HC_ACTION) Then
                Select Case wParam
                    Case WM_MOUSEMOVE
                        RaiseEvent Mouse_Move()
                    Case WM_LBUTTONDOWN
                        RaiseEvent Mouse_Left_Down()
                    Case WM_LBUTTONUP
                        RaiseEvent Mouse_Left_Up()
                    Case WM_LBUTTONDBLCLK
                        RaiseEvent Mouse_Left_DoubleClick()
                    Case WM_RBUTTONDOWN
                        RaiseEvent Mouse_Right_Down()
                    Case WM_RBUTTONUP
                        RaiseEvent Mouse_Right_Up()
                    Case WM_RBUTTONDBLCLK
                        RaiseEvent Mouse_Right_DoubleClick()
                    Case WM_MBUTTONDOWN
                        RaiseEvent Mouse_Middle_Down()
                    Case WM_MBUTTONUP
                        RaiseEvent Mouse_Middle_Up()
                    Case WM_MBUTTONDBLCLK
                        RaiseEvent Mouse_Middle_DoubleClick()
                    Case WM_MOUSEWHEEL
                      RaiseEvent Mouse_Wheel()
                End Select
            End If
    I cant use handles because it says i need a withevents statement but i cant create a variable with a withevents beacuse a module can't be declared as a type, help
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    #2 stevemk14ebr, May 4, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    nvm i got it i found a great post on how to use addHandler used this code
    Code:
     
    'in form load
    'mouse_left_doubleclick is the event name and mousehook is the module name
    AddHandler MouseHook.Mouse_Left_DoubleClick, AddressOf Me.mouseleftdc
    End Sub
    'this method was named mHook_Mouse_Left_DoubleClick but i renamed it for ease
    Private Sub mouseleftdc()
            MessageBox.Show("double click")
        End Sub
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...