Ver Mensaje Individual
  #117 (permalink)  
Antiguo 16/05/2006, 15:54
Avatar de RootK
RootK
Moderador
 
Fecha de Ingreso: febrero-2002
Ubicación: México D.F
Mensajes: 8.004
Antigüedad: 22 años, 10 meses
Puntos: 50
Tema: Windows Forms (tips and tricks)
Pregunta: Como poder arrastar mi forma si no tiene la barra de título (FormBorderStyle.None) ?
Respuesta:

C#
Cita:
using System.Runtime.InteropServices;
............

public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HTCAPTION = 0x2;

[DllImportAttribute ("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

[DllImportAttribute ("user32.dll")]
public static extern bool ReleaseCapture();

private void Form2_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}

extraído de aqui
vb.net
Cita:
Imports System.Runtime.InteropServices
...

Public Const WM_NCLBUTTONDOWN As Int32 = &HA1
Private Const HTCAPTION As Int32 = &H2

<DllImportAttribute("user32.dll")> _
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function

<DllImportAttribute("user32.dll")> _
Public Shared Function ReleaseCapture() As Boolean
End Function

Private Sub Form1_MouseDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
ReleaseCapture()
SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0)
End Sub