moving a window without using the title bar?

Jan 25 2005 7:57 PM
i've seen it done before, but i cant seem to do it right. i want to be able to drag the window over the screen while the mouse button is held down on a panel, but when i click on the panel, the whole window moves so that the top right corner is directly under the pointer. i want to be able to move it from where it is, like a title bar, not have it teleport to under my cursor before i move it. so far the moving it part of the code goes like this: private void panel1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { followmouse=true; } private void panel1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { followmouse=false; } private void panel1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if(followmouse) { // this.DesktopLocation = new Point((e.X - this.Left)+this.Left,(e.Y - this.Top)+this.Top); //this.DesktopLocation = new Point(e.X,e.Y); this.DesktopLocation = Control.MousePosition; } } the commented out parts are the old attempts, and they work worse than my current attempt.

Answers (2)