Passing a MouseDown event

ALX

Well-known member
Joined
Nov 16, 2005
Messages
253
Location
Columbia, SC
Programming Experience
10+
I'd like to perform the following stunt on a form in my app. When the user clicks a label, I want the label to disappear and pass the mousedown event to the underlying panel or picturebox. Getting the label to disappear, of course, is easy. I don't have the resources to find out how to pass the MouseDown event to the picturebox that was a temporary container for the label though. I'll need the mouse cursor co-ordinates to be passed also.
*** thanx in advance !!!
 
Hello

You can easily pass the MouseDown Event on (Click don't have the XY coordinates).

VB.NET:
Private Sub Label1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown
        Me.PictureBox1_MouseDown(Me, New MouseEventArgs(e.Button, e.Clicks, e.X, e.Y, e.Delta))
    End Sub
 
The sender parameter should be the class instance for that event that "raised it", e MouseEventArgs parameter can passed directly without change, but would be correct to change the mouse x/y location relative to the picturebox:
VB.NET:
Dim p As Point = PictureBox1.PointToClient(Label1.PointToScreen(e.Location))
Me.PictureBox1_MouseDown(Me.PictureBox1, New MouseEventArgs(e.Button, e.Clicks, p.X, p.Y, e.Delta))
 
Geesh !!! That's entirely too simple. 'Don't know why I thought that I needed to raise an event to accomplish this. 'Guess I've seen too many other posts where somebody was getting chastized for calling event handlers directly. I should have thought of this myself! Any way, let me take this to the next step. When the user clicks the label and the label disappears it begins a process that starts with the MouseDown event for the PictureBox. It needs to continue with any subsequent MouseMove events in the PictureBox so that a path can be traced out beginning at the MouseDown (e.x, e.y) point. Passing the MouseDown event & co-ordinates to the PictureBox is working now, (thanks to your response) but I can't seem to trap any subsequent MouseMove events. Any thoughts on that?
 
Hello.

I hope I got this right.
If the label has disappeared, you could send it behind the Picturebox with SendToBack and back would be BringToFront), and then use the Picturebox MouseMove Event directly. Combined with a Boolean which gets set the moment the Label is clicked and an Array where you store at each MouseMove the new values, you should be able to track the path with ease.

Bobby
 
Well I stumbled onto the answer to the MouseMove problem by putting "Label1.Capture = False and Me.PictureBox1.Capture = True in the Label1.MouseDown event handler. Apparently the Label remains the active control even after it has been made invisible until a MouseUp event occurs. Thanks for your help on this !!!
 
Last edited:
Back
Top