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


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
        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)

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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...


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
    End Sub

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

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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

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

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

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.