[C# .NET] Moving WinForm without top-bar.


How to move a WinForm without top-bar control.

Some times can happen to move a Window without border, for example for a window of credits like SkyWhi:


uploaded_image


Once again is necessary to use InteropServices to emulate Window Manager control in an other point of window:


using System.Runtime.InteropServices;
...

public const int WM_NCLBUTTONDOWN = 0xA1;

public const int HT_CAPTION = 0x2;

//Include external method to pilot a window.
[DllImportAttribute(\"user32.dll\")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

//Include external method to capturing a window.
[DllImportAttribute(\"user32.dll\")]
public static extern bool ReleaseCapture();

//Window MouseDown event handler.
private void Application_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
   {
    ReleaseCapture();
    SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
   }
}

--
Enjoy your windows! :)


Article published on: Dario Maggiari Blog - NecroBlog - http://necrosoft.altervista.org/NecroBlog/
Reference URL: http://necrosoft.altervista.org/NecroBlog//index.php?mod=read&id=1150655866