Windows Form Application - Borderless Click+Drag

Ok, so I'll make this short... I have a Windows Form Application coded with Microsoft Visual C++ Express 2010, and it's borderless. Borderless windows cannot be moved by means of the title bar (There is none), so I wanted it to move by clicking anywhere in the background and dragging the window around. So far, the code below is what I have. It works for the most part, just not how I expected. The window seems to only move half as far as the mouse does when dragging (I could multiply the mouse movement by 2, or whatever ratio it's off by, in the function but that's a dirty fix), and it has some odd shaking while the mouse button is down. Any assistance would be greatly appreciated.

A couple of things I think may be the problem:
1. The mouse X and Y events are not always being sent correctly, so the coordinates are off on some of the updates.
2. When updating the window location, something else is conflicting causing the window to keep switching between the conflicted position and the position I'm setting.
3. When overriding the virtual function it is calling itself recursively from within, though the override should only apply to Form1 (My instance of Form), not the entire original Form class.

Globals:
bool followmouse = false;
System::Drawing::Point windowlocation, mouselocation;


Functions:
public: virtual System::Void OnMouseDown(MouseEventArgs^ e) override {
if (!followmouse) {
followmouse = true;
//Get coords inside window
mouselocation = Point(e->X, e->Y);
//Get window location
windowlocation = this->Location;
}
Form::OnMouseDown(e);
}
public: virtual System::Void OnMouseMove(MouseEventArgs^ e) override {
if (followmouse) {
this->Left = windowlocation.X + (e->X - mouselocation.X);
this->Top = windowlocation.Y + (e->Y - mouselocation.Y);
}
Form::OnMouseMove(e);
}
public: virtual System::Void OnMouseUp(MouseEventArgs^ e) override {
followmouse = false;
Form::OnMouseUp(e);
}
Last edited on
Topic archived. No new replies allowed.