Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Respond to ANY mouse event ANYWHERE on a form with ONE sub routine

Posted on 2006-11-11
6
Medium Priority
?
188 Views
Last Modified: 2010-04-23
I need to respond to a mouse click anywhere on a form.  I'm incorporating this into about 25 forms.  I would like to create a sub routine that allows me to just paste into each one of them without having to customize for each form based on particulars of each form.

I've tried me.mousedown, me.click, mybase.click, mybase.mousedown

I have several group boxes on the form and I get no result when clicking anywhere inside the group boxes, but if I click outside of the group boxes mybase and me.click or .mousedown execute.  Also, any of these forms may have text boxes, combo boxes, listviews, etc.

Is there ONE event that captures for any and all mouse activity throughout a form?


Phil Tate
0
Comment
Question by:TSFLLC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 13

Accepted Solution

by:
newyuppie earned 1000 total points
ID: 17922965
i think the only option you have is to add a loop to cycle through every control you want to handle the mouse click event, and wire then via AddHandlers all to 1 particular sub

something in the ballpark of:

for each ctl as control in me.controls
  addhandler ctl.mousedown, address of AllMouseDown
next ctl

in the Load event. and an additional sub

Private Sub AllMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
  'do stuff
End Sub
0
 
LVL 34

Expert Comment

by:Sancler
ID: 17923557
I think there may be an API that might help you to do this, but APIs are not my forte.  

In VB.NET, I would agree with newyuppie, only adding that you will need to make your code recursive because you have textboxes (etc.) within controls (e.g. groupboxes).  Something like this (not tested).

Private Sub AddMouseHandler (ByVal ctl As Control)
      If ctl.HasChildren Then
         AddMouseHandler(ctl)
      End If
      addhandler ctl.mousedown, address of AllMouseDown
Exit Sub

called in Load event like this

for each ctl as control in me.controls
  AddMouseHandler(ctl)
next ctl

Roger
0
 
LVL 34

Assisted Solution

by:Sancler
Sancler earned 1000 total points
ID: 17925321
Oops.  I shouldn't code onto the screen at such a (UK) late hour ;-(

This

Private Sub AddMouseHandler (ByVal ctl As Control)
      If ctl.HasChildren Then
         AddMouseHandler(ctl)
      End If
      addhandler ctl.mousedown, address of AllMouseDown
Exit Sub

should be this

Private Sub AddMouseHandler (ByVal ctl As Control)
      If ctl.HasChildren Then
         For Each subCtl As Control In ctl.Controls
            AddMouseHandler(subCtl)
         Next
      End If
      addhandler ctl.mousedown, address of AllMouseDown
Exit Sub

Roger
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

636 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