Solved

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

Posted on 2004-11-01
177 Views
Last Modified: 2010-04-23
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
Question by:jflanner
    7 Comments
     
    LVL 96

    Accepted Solution

    by:
    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
     
    LVL 5

    Expert Comment

    by:Ignacio Soler Garcia
    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
     
    LVL 96

    Expert Comment

    by:Bob Learned
    So many options, and so little feedback :(

    Bob
    0
     
    LVL 5

    Expert Comment

    by:Ignacio Soler Garcia
    Hey jflanner, have you checked the responses?

    SoMoS
    0
     
    LVL 96

    Expert Comment

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

    Bob
    0
     
    LVL 5

    Expert Comment

    by:Ignacio Soler Garcia
    Ok, then fire this one will be ok?
    0
     
    LVL 96

    Expert Comment

    by:Bob Learned
    Unfortunately, I need to wait for 21 days of inactivity before closing, but that day will come soon enough :)

    Bob
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now