471,108 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

new Moving function

Hi,

I want move my form with mouse when I press button over a different position
from normal bar of title.

I set MouseUp, MouseDown and, MouseMove events and all works good.

is it possible work with a more intelligent method ?

When I move a normal form only its border is visible.
How can I do this effect in my personal moving functions ?

Thanks a Lot

Nov 15 '05 #1
2 1422
Hi,
To move the windows by yourself, you have to implement mousemove. To make
sure that you drag from your form, you have
to override MouseDown. Therefore, implement 3 methods is the only way to
move your form.
To have the border of the windows move, you should draw a rectangle with
Graphics object in MouseMove Event.
"willem" <wi****@libero.it> wrote
Hi,

I want move my form with mouse when I press button over a different position from normal bar of title.

I set MouseUp, MouseDown and, MouseMove events and all works good.

is it possible work with a more intelligent method ?

When I move a normal form only its border is visible.
How can I do this effect in my personal moving functions ?

Thanks a Lot


Nov 15 '05 #2
There is a clever way to achieve this, and have it work the same
way as when the window is moved using the title bar.

The trick is to override the WndProc method of the form and
handle the WM_NCHITTEST message and return HTCAPTION
for the appropriate mouse coordinates.

As a demo, create a new form and add this code to it:

protected override void WndProc(ref Message m)
{
// from WinUser.h
const int WM_NCHITTEST = 0x0084;
const int HTCAPTION = 2;

if (m.Msg == WM_NCHITTEST)
{
Point screenPoint = new Point((int)m.LParam % 65536,
(int)m.LParam / 65536);
Point clientPoint = PointToClient(screenPoint);

// Check that the user clicked in the area to be
// used for moving the window, in this case a circle
// of radius 50 centered at coordinates 100, 100
if (Math.Pow(clientPoint.X - 100, 2) +
Math.Pow(clientPoint.Y - 100, 2) < 50 * 50)
{
m.Result = (IntPtr)HTCAPTION;
return;
}
}
base.WndProc(ref m);
}

protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.FillEllipse(Brushes.Blue, 50, 50, 100, 100);
}

This obviously depends on how Windows handles messages, so it
probably isn't 100% "future proof". But right now it works great.

- Magnus
"willem" <wi****@libero.it> wrote in message
news:OG*************@TK2MSFTNGP12.phx.gbl...
Hi,

I want move my form with mouse when I press button over a different position from normal bar of title.

I set MouseUp, MouseDown and, MouseMove events and all works good.

is it possible work with a more intelligent method ?

When I move a normal form only its border is visible.
How can I do this effect in my personal moving functions ?

Thanks a Lot

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Diogo Alves - Software Developer | last post: by
1 post views Thread by mmalloc | last post: by
3 posts views Thread by Cartoper | last post: by
10 posts views Thread by cjparis | last post: by
1 post views Thread by rsteph | last post: by
15 posts views Thread by mcjason | 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.