drag window wothout titlebar
-
Hi. How do i drag and move a window using the mouse, when the window do not have a titlebar??? I thought of using MouseDown, MouseMove and MouseUp to move it, but i can't seem to get it to work :-( As their an easier way??
-
Hi. How do i drag and move a window using the mouse, when the window do not have a titlebar??? I thought of using MouseDown, MouseMove and MouseUp to move it, but i can't seem to get it to work :-( As their an easier way??
may be this code can help you add mousemove event and form_load event to your form and three variables x,y,click,first to your class check this code is true or not.
private int x,y; bool click=false; bool first=false; private void Form1_MouseMove(object sender,System.Windows.Forms.MouseEventArgs e) { if(e.Button==MouseButtons.Left) { if(click&&first) this.Location=new Point(this.Location.X+e.X- x,this.Location.Y+e.Y-y); x=e.X; y=e.Y; click=true; first=!first; } else click=false; } private void Form1_Load(object sender, System.EventArgs e) { x=this.Location.X; y=this.Location.Y; }
-
Hi. How do i drag and move a window using the mouse, when the window do not have a titlebar??? I thought of using MouseDown, MouseMove and MouseUp to move it, but i can't seem to get it to work :-( As their an easier way??
Back in the days of MFC, this was as simple as adding a handler for the WM_NCHITTEST (0x0084) message and returning HTCAPTION (2). I just tried doing the equivalent of that on a C# project of mine but it didn't work! :confused:
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0084)
m.Result = (IntPtr)2;
base.WndProc(ref m);
}What's also weird is that m.Result always comes in with a value of 0, no matter where I place the cursor on the form. :sigh: By the way, how did you create a form without a titlebar? Regards, Alvaro
He who laughs last, thinks slowest.
-
Back in the days of MFC, this was as simple as adding a handler for the WM_NCHITTEST (0x0084) message and returning HTCAPTION (2). I just tried doing the equivalent of that on a C# project of mine but it didn't work! :confused:
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0084)
m.Result = (IntPtr)2;
base.WndProc(ref m);
}What's also weird is that m.Result always comes in with a value of 0, no matter where I place the cursor on the form. :sigh: By the way, how did you create a form without a titlebar? Regards, Alvaro
He who laughs last, thinks slowest.
I think I've seen someone doing it in C# using Windows message processing like you show... Forms can be created without titlebars via myForm.FormBorderStyle = FormBorderStyle.None The graveyards are filled with indispensible men.
-
may be this code can help you add mousemove event and form_load event to your form and three variables x,y,click,first to your class check this code is true or not.
private int x,y; bool click=false; bool first=false; private void Form1_MouseMove(object sender,System.Windows.Forms.MouseEventArgs e) { if(e.Button==MouseButtons.Left) { if(click&&first) this.Location=new Point(this.Location.X+e.X- x,this.Location.Y+e.Y-y); x=e.X; y=e.Y; click=true; first=!first; } else click=false; } private void Form1_Load(object sender, System.EventArgs e) { x=this.Location.X; y=this.Location.Y; }
Great! that was exatly what i needed! thanks a bunch.