Mover formularios sin bordes

En ocasiones se desea crear un formulario sin bordes como por ejemplo un Login

El problema aparece cuando intentamos moverle porque se queda en medio de la pantalla y nos tapa el resto de aplicaciones/iconos, para solventarlo deberemos de hacer lo siguiente.

  • Abrimos el código del formulario en cuestión.
  • Agregar al código siguiente:
[System.Runtime.InteropServices.DllImport("user32.DLL", EntryPoint = "ReleaseCapture")]
        private extern static void ReleaseCapture();
        [System.Runtime.InteropServices.DllImport("user32.DLL", EntryPoint = "SendMessage")]
        private extern static void SendMessage(System.IntPtr hWnd, int wMsg, int wParam, int lParam);
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(this.Handle, 0x112, 0xf012, 0);
        }
  • Quedaría algo así:
namespace Interfaz
{
    public partial class Login : Form
    {
        [System.Runtime.InteropServices.DllImport("user32.DLL", EntryPoint = "ReleaseCapture")]
        private extern static void ReleaseCapture();
        [System.Runtime.InteropServices.DllImport("user32.DLL", EntryPoint = "SendMessage")]
        private extern static void SendMessage(System.IntPtr hWnd, int wMsg, int wParam, int lParam);
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(this.Handle, 0x112, 0xf012, 0);
        }
  • Iremos a las propiedades del formulario
  • Seleccionaremos lo siguiente:


Donde “Form1_MouseDown” es el nombre de la función, que podremos usar el que mas nos interese.

  • Guardamos el trabajo.
  • Iniciamos el proyecto y ya debería de funcionar.

Ejemplo del código funcionando: <html><a href=“https://dl.dropboxusercontent.com/u/19507761/EjemploFormMovil.7z” target=“_blank”>Descargar</a></html> (Alojado en dropbox y comprimido con 7Z).


Navegación

Software de programación

Ayuda al servidor