M
Mythran
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
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