How to move window witout a title bar?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want my window not to have title bar, but then the problem arises, how to
move such a window. Is it possible to make window move by moving mouse
anywhere on that window?
 
Jurate,

This is what I would do. I would handle the mouse down and mouse up
events on the form. When the mouse is held down, I would set a flag
indicating that the mouse button is pressed down, and set it to false on the
mouse up event. Also, in the mouse down event, I would store the current
location of the mouse.

Then, I would add an event handler for the mouse move event. In that
event, if your flag is set, then I would get the current mouse location.
Compare it with the previous mouse location, finding the difference between
the two. Adjust the form's Location property by that difference and it will
move. The important thing is to also store the current location of the
mouse after all of this.

Hope this helps.
 
Hi Jurate,

You need to override form's WndProc method and check for WM_NCHITTEST
message


private const int WM_NCHITTEST = 0x0084;
private const int HTCLIENT = 1;
private const int HTCAPTION = 2;

protected override void WndProc(ref Message m)
{
base.WndProc (ref m);
if(m.Msg == WM_NCHITTEST && m.Result == new IntPtr(HTCLIENT))
m.Result = new IntPtr(HTCAPTION);
return;

}

Now grab the window somewhere in its client area and move it around.
 
Back
Top