?
Solved

.NET Control - child controls (e.g. labels) do not listen to my mouseclick events

Posted on 2006-03-19
5
Medium Priority
?
239 Views
Last Modified: 2010-04-17
I have a user control that listens to certain onmousedown and onmouseover events.
The control also holds a few labels.

When I click on the control over those few labels, the onmousedown/over event listeners are not invoked.

So here comes my question: How to have a control including all its child to listen to all mouseclick events?
0
Comment
Question by:jtjli
  • 2
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
LordWabbit earned 400 total points
ID: 16234489
When I click on the control over those few labels, the onmousedown/over event listeners are not invoked.

Sounds like the control you are trying to click on is actually behind your label and so the label is catching the mouse events and not the control behind it.  You might want to reposition your controls a bit or something.

Also to programatically add event handlers you would do something like this

Addhandler label1.MouseDown, Addressof MyMousdownHandler
0
 
LVL 6

Assisted Solution

by:cubixSoftware
cubixSoftware earned 600 total points
ID: 16235512
Like LordWabbit suggests you can use the AddHandler, or simply define multiple Handles entries for your MouseDownProcedure... e.g.

Currently you may have

Private Sub usrControl_MouseDown(ByVal sender As Object, ByVal e As system.Windows.Forms.MouseEventArgs) Handles usrControl.MouseDown        

... code to do something

End Sub

But you could easily change to

Private Sub usrControl_MouseDown(ByVal sender As Object, ByVal e As system.Windows.Forms.MouseEventArgs) Handles usrControl.MouseDown, Label1.MouseDown, Label2.MouseDown, Label3.MouseDown          

... code to do something

End Sub


HTH

0
 

Author Comment

by:jtjli
ID: 16242582
>> Sounds like the control you are trying to click on is actually behind your label and so the label is catching the mouse events and not the control behind it

If my control is above my labels, then my labels will be hidden, right?  Or is there any workaround..
0
 
LVL 6

Assisted Solution

by:cubixSoftware
cubixSoftware earned 600 total points
ID: 16245144
>>If my control is above my labels, then my labels will be hidden, right?

Your user control is acting as a container to the labels. If you made the control higher in the Z-Order then you probably won't actually see the labels.

The behaviour you are experiencing can also be replicated by having a groupbox with a couple of labels within it.

The solution I proposed above is very straight forward so I am surprised you are still looking for another workaround, or is there some more issues we need to know about?
0
 

Author Comment

by:jtjli
ID: 16253718
i've accepted that there's no direct solution
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

Make the most of your online learning experience.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Simple Linear Regression

864 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