471,610 Members | 1,305 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,610 software developers and data experts.

Moving window

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

Dec 5 '05 #1
2 1279
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Piotrekk" <Pi*************@gmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
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

Dec 5 '05 #2
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

"Piotrekk" <Pi*************@gmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
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

Dec 6 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Andi B | last post: by
2 posts views Thread by willem | last post: by
5 posts views Thread by Jon Masterson | last post: by
7 posts views Thread by =?Utf-8?B?TW9iaWxlTWFu?= | last post: by
1 post views Thread by rsteph | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.