473,395 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Moving form with MouseMove or WndProc

Which *should* I use? Which is more elegant? IMO, the WndProc override is
more elegant but probably shouldn't be used for this?

Snip code below:

Variation #1:
private Point mLastMousePoint;

private void Form1_MouseDown(object sender, MouseEventArgs e)
{
mLastMousePoint = new Point(e.X, e.Y);
}

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) == MouseButtons.Left) {
this.Location = new Point(
this.Left - (mLastMousePoint.X - e.X),
this.Top - (mLastMousePoint.Y - e.Y)
);
}
}

Variation #2:
private const int WM_NCHITTEST = 0x84;
private const int HT_CLIENT = 0x1;
private const int HT_CAPTION = 0x2;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);

if (m.Msg == WM_NCHITTEST && m.Result.ToInt32() == HT_CLIENT) {
m.Result = (IntPtr) HT_CAPTION;
}
}
This is rewritten untested uncompiled code...should be enough info for the
question I want answered, but if it's not, lemme know :)

Thanks,
Mythran
Jan 5 '07 #1
0 2210

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: willem | last post by:
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...
0
by: Sam Sungshik Kong | last post by:
Hello! If I understand correctly, MouseMove event is triggered when the mouse moves (ie when point changes). I, however, found out that it's triggered even if the mouse is not moving. What I...
5
by: Pablo Cedeno | last post by:
Hi all, I'm having a problem with a form position. I need to prevent the user to drag the window. I tried to maximize the window but i still can move the window. I found something about...
2
by: Bevo | last post by:
I have a form with the FormBorderStyle = None, i.e. no caption bar, no borders. But I'd still like to have the possibility to move this form by using the mouse. Could anybody tell me what to...
1
by: dsa | last post by:
Is there a way to determine when a user has stopped moving a form? I know the move event tells when the form is being moved but how do I know when the form has stopped moving?
3
by: AM Hulshoff | last post by:
Can someone tell me how I can move an object, in this case a listbox, over a form. The code below works, but not when the form is custom sized. It works perfectly when the form is maximized. And...
1
by: Chris Dunaway | last post by:
If I have a form in my project for which I have set the border style to None, I can use the code below to enable moving the form by clicking and dragging anywhere on the form: protected override...
4
by: David Gouge | last post by:
Hi All, I have a borderless form that i can drag around fine when dragging anywhere on the form by using the following code: protected override void WndProc(ref Message m) { const int...
8
by: James Arnold | last post by:
I currently have a borderless form, which I am subclassing to allow dragging & dropping: Protected Overrides Sub WndProc(ByRef m As Message) Select Case m.Msg Case 132 'Click & Drag Form...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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,...

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.