MouseDown Handler

  • Thread starter Thread starter Merlin
  • Start date Start date
M

Merlin

I have created a UserControl which has a label; what I wish to do is place
this UserControl on a form and then trap the Mouse Down event, whenever
someone clicks my control. My problem is that the Mouse Down event for the
UserControl is not detected if the mouse cursor is placed over the label
inside the control, i.e the label within the control has trapped the event
so I don't get to see it.

I've looked at adding the label mousedown handle event to the controls
mousedown, but that doesn't work either; I can get around this easy enough
by making my own event handler - but just wondered if there were another
way.

Thanks,
Merlin
 
Instead of using the label, you could draw the text in the Paint event of
your usercontrol, i.e.

Public Sub OnPaintControl(ByVal sender As Object, ByVal e As PaintEventArgs)
Handles MyBase.Paint
e.Graphics.DrawString(...)
End Sub

If the text of the label changed, then call Me.Invalidate to redraw the
text.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations
 
Hi Merlin,

I've got the following:

Private Sub UserCtrlFoo_MouseDown (ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles MyBase.MouseDown, TextBox1.MouseDown, Label1.MouseDown

TextBox1.Text = sender.ToString
End Sub

and it shows each of the controls correctly when I click on them.

Perhaps it's worth having another go? If it still fails, post your code.

Regards,
Fergus

ps. When you do get it working, if you are using them, remember that the mouse
X and Y are within the clicked control.
 
Merlin said:
I have created a UserControl which has a label; what I wish to do is place
this UserControl on a form and then trap the Mouse Down event, whenever
someone clicks my control. My problem is that the Mouse Down event for the
UserControl is not detected if the mouse cursor is placed over the label
inside the control, i.e the label within the control has trapped the event
so I don't get to see it.

I've looked at adding the label mousedown handle event to the controls
mousedown, but that doesn't work either; I can get around this easy enough
by making my own event handler - but just wondered if there were another
way.

Untested: You may want to call 'MyBase.OnMouseDown(...)' in the handlers of the other controls on the user control.
 
Back
Top