473,473 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1501
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Diogo Alves - Software Developer | last post by:
Greetings I would like to knowhow can I put a sliding panel... I've done this: if (panel1.Width < 300) { while (panel1.Width < 300) { panel1.Width = panel1.Width + 40;
1
by: mmalloc | last post by:
I have the following code to move some text with javascript that works both on ie and ff. I can't make it XHTML compatble. If i remove the doctype info it will work. I'm sorry to bother with such...
1
pavlov
by: pavlov | last post by:
Hello everybody. I've this problem: I'm making a jpg moving horizontally from left to right in my page. I'd like to make it start moving from the left off-screen side. I tried using position...
3
by: Cartoper | last post by:
I would like to design a web page as follows: There is a box (box A) with some things in it that the user can click on. When an item is clicked, another box (box B) moves in from the right side...
10
by: cjparis | last post by:
Hello everyone. If anyone can give me a hand I would be gratefull Am doing a site which requires a moving element and have used DHTML to do it. Have a simple Browser detect script to sort IE...
3
by: cjparis | last post by:
Hello All I built a simple script to move a div tag with a MouseOver event handler. This worked fine in Safari but would not work in Netscape and Firefox Can anyone help? You can see it...
1
by: rsteph | last post by:
I bought a book to help me learn to use DirectX with windows programming. It's first trying to walk me through some basic windows programming and graphics before getting into DirectX. I'm trying to...
0
by: SuzK | last post by:
I am trying to calculate in VBA in Access 2002 a moving average and update a table with the calculations. Fields in my WeeklyData table are Week Ending (date) ItemNbr (double) Sales Dollars...
15
by: mcjason | last post by:
I saw something interesting about a grid pair puzzle problem that it looks like a machine when you find each that work out the way it does and say with all the others that work out the way they...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.