-
click and drag form
I was wondering on how to click on the form anywhere and be able to drag it.
I found a sample on how to do this, but it's in C++. Here's what it looks like:
void CNCHitDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
CDialog::OnLButtonDown(nFlags, point);
// fake windows into thinking your clicking on the caption does not
// maximize on double click
PostMessage( WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM( point.x, point.y));
}
If anyone knows how to translate this, that would be a huge help :)
thank you.
-
Ok, nevermind, i found out how to do it. If anyone else is curious on how to do it. I found a way to sort of "cheat" i guess.
What you do is place a picturebox on the form and dock it so it takes up the whole form. Once you do this, simply select the events button and double click on MouseMove and MouseDown events.
for the MouseDown event this is the code:
private void pictureBox1_MouseDown(
object sender, System.Windows.Forms.MouseEventArgs e)
{
ptOffset = new Point(-e.X - pictureBox1.Left,
-e.Y - pictureBox1.Top);
}
--- I should note ptOffest. You have to declair it under where your controls are.. private Point ptOffset;
...Now for MouseMove event:
private void pictureBox1_MouseMove(
object sender, System.Windows.Forms.MouseEventArgs e)
{
if( e.Button==MouseButtons.Left)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(ptOffset.X, ptOffset.Y);
this.Location = mousePos;
}
}
There ya go.