Moving window

  • Thread starter Thread starter Piotrekk
  • Start date Start date
P

Piotrekk

Hi.
I wanna move window, by clicking its body ( not the strip ).
Which event should i catch.
I tried with mousedown, but then i only can update position of window,
once.
My task is to change it in real mode ( until mousebutton is up).
Can anyone help?
PK
 
Piotreek,

Are you moving the window in relation to the mouse moving? If that is
the case, then you want to check the MouseMove event, and then set the
position of your window there.

Hope this helps.
 
Well I wrote this class once, it may help you:

--------------------------------------------
internal class FormDrag
{
Form _form=null ;
int _y = 0, _x = 0;
private bool _mousedown = false;

public FormDrag(Form form)
{

if (form == null)
throw new ArgumentNullException("Must pass a form instance.");
_form = form;
_form.MouseMove += new MouseEventHandler(_form_MouseMove);
_form.MouseDown += new MouseEventHandler(_form_MouseDown);
_form.MouseUp += new MouseEventHandler(_form_MouseUp);

}

void _form_MouseUp(object sender, MouseEventArgs e)
{
_mousedown = false;
}

void _form_MouseDown(object sender, MouseEventArgs e)
{
_mousedown = true;
_y = e.Y;
_x = e.X;

}

void _form_MouseMove(object sender, MouseEventArgs e)
{

if (_mousedown)
{
int a = _y - e.Y;
_form.Top -= a;
a = _x - e.X;
_form.Left -= a;


}
}
}
--------------------------------------------
To use this class, what you do is; on the load event of your form you write:

_formdrag = new FormDrag(this);

where _formdrag is a variable, of type FormDrag class, at class scope.

I hope this helps you.

Ab.
http://joehacker.blogspot.com
 
Back
Top