Click here to Skip to main content
15,896,526 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
I have written a control to move a usercontrol at run time it was working fine. But when i added a label control and docked it to fill this has stopped moving at runtime.
Can anybody tell me the solution how this is possible

code is as bellow :

Private Sub CtrlMover1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles CtrlMover1.MouseDown
       If e.Button = Windows.Forms.MouseButtons.Left Then
           CtrlMover1.Capture = False
           Dim msg As Message = Message.Create(CtrlMover1.Handle, WM_NCLBUTTONDOWN, New IntPtr(HTCAPTION), IntPtr.Zero)
           Me.DefWndProc(msg)
       End If
   End Sub




But when i handles MouseDown, MouseMove, and MouseUp the Picture on the form where i put user control flickers
Posted
Updated 23-May-11 20:09pm
v3

This is not related to dock. By the way, why do you dock the Label to DockStyle.Fill, ever? I would understand is it is DockStyle.Top.

Now, it looks like you motion is messed up:

1) You need need to handle MouseDown, MouseUp and MouseMove.

2) You never need to create any message and use P/Invoke for any Windows API for this purpose. Instead, you just need to change Location of the object you're moving.

3) You may or may not use mouse capture. If you do it, you need to start mouse capture in the handler of MouseDown (not stop capturing), do actual move in the handler of MouseMove and stop capture in the handler of MouseUp, with the same button, presumably left one.

—SA
 
Share this answer
 
The UserControl you're moving is a container with its own surface. You're probably handling the UserControl events to do the runtime-move with the mouse. Now that there is a label that is covering the entire UserControl space, the mouse events are no longer going to the UserControl, but to the label.

Either change the label so you can see the UserControl surface or rewrite the eventhandlers to use the label mouse events instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900