Hi everybody !
I have a question to ask... I set the FormBoderStyle to None, and the Form can not be moved. I want to move the Form by 'mouse down' onto a control (eg. :Picture Box). I have tried but I have more errors with form position values, X,Y...
Could you help me with your codes
Thank you very much, ![]()

Move the Form (that FormBoderStyle is None)?
madmax2003
Here it is, the code you have been looking for!
protected
override void WndProc(ref Message m){
base.WndProc(ref m); int WM_NCHITTEST = 0x84; if (m.Msg == WM_NCHITTEST){
int HTCLIENT = 1; int HTCAPTION = 2; if (m.Result.ToInt32() == HTCLIENT)m.Result = (
IntPtr)HTCAPTION;}
}
Richard Hardy
You can use the DragMove() method in a event of mouse left button down.
private void obj_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) {this
.DragMove();}
twolfkg
You will have to handle the event for mouse down, up, and move.
In the mouse move event you will move the form if a mouse down event has happened but not yet a mouse up event. This will let the move form code only to run when mouse button is down.
When you detect a mouse down event you need to record the current x, y positions of the mouse, it is in the MouseEventArg. Then in the mouse move event you can calculate the how much the mouse have been moved in each direction and move the form accordingly.
This is pseudo code just to demonstrate flow.
EDIT: Ooops, wrote the pseude code in VB style instead of C# style
Boolean bIsMoving;
Point loc;
void OnMouseDown(MouseEventArg mea)
{
bIsMoving = true;
loc = mea.Location;
}
void OnMouseUp(MouseEventArg mea)
{
bIsMoving = false;
}
void OnMouseMove(MouseEventArg mea)
{
if (true == bIsMoving)
{
this.Left = this.Left + mea.Location.X - loc.X;
this.Top = this.Top + mea.Location.Y - loc.Y;
}
}
Rajesh Patel
hi,
Is your problem solved
Thank you,
Bhanu.
Ondis
hi,
you want to move the form onto a control, strange isn't it