[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

I need a way for all mouse down/up events to be processed by a single event handler

Folks:

I'm putting together a rather complicated GUI.  Basically, I want to respond to mouse move events if the left mouse button is depressed.  Thus, I want to capture mouse down and mouse up.  

What I'd lilke to do is capture the event when it happens on the menu, or any component in the menu.  I have coded:

    Private Sub cBoggleGUI_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
        If e.Button = MouseButtons.Left Then
            LeftMouseDown = True
        Else
        End If
    End Sub

This works for all mouse down events that cooure on the menu, but it does not handle any mouse downs the occure on components on the menu.

Is there a way to define an event that handles the menu, and all components?  Or do I need to program a mouse down for all of the components.  (yuc)

Ideas...
0
jflanner
Asked:
jflanner
  • 4
  • 3
1 Solution
 
Bob LearnedCommented:
If the signatures are the same you can do something like this:

Private Sub MouseDownEvent(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown, Menu1.MouseDown, Button1.MouseDown...

Bob
0
 
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
Do it like this:

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private WithEvents comp As Windows.Forms.Control
(...)

    Private Sub AddHandlerToControls()
        Dim index As Integer

        For index = 0 To Me.Controls.Count - 1
            AddHandler Me.Controls.Item(index).Click, AddressOf sss
        Next
    End Sub

    Public Sub sss(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MsgBox("ddd")
    End Sub
End Class
0
 
Bob LearnedCommented:
So many options, and so little feedback :(

Bob
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
Hey jflanner, have you checked the responses?

SoMoS
0
 
Bob LearnedCommented:
Yeah, as cleanup volunteer, I see a lot of abandoned questions.

Bob
0
 
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
Ok, then fire this one will be ok?
0
 
Bob LearnedCommented:
Unfortunately, I need to wait for 21 days of inactivity before closing, but that day will come soon enough :)

Bob
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now