viernes, 20 de enero de 2012

VB.Net] Mover un form o PictureBox con el ratón

Haz lo siguiente:
Abre un nuevo proyecto
Pega un PictureBox



El código



Public Class Form1 
    Private Const WM_NCLBUTTONDOWN = &HA1 
    Private Const HTCAPTION = 2 

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ 
                 (ByVal hwnd As Integer, ByVal wMsg As Integer, _ 
                  ByVal wParam As Integer, ByVal lParam As String) As Integer 
    Private Declare Sub ReleaseCapture Lib "user32" () 

'Desplazamiento de la PictureBox 
    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove 
        Dim lHwnd As Int32 
        lHwnd = PictureBox1.Handle 
        If lHwnd = 0 Then Exit Sub 
        ReleaseCapture() 
        SendMessage(lHwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&) 
    End Sub 

'Desplazamiento del form 
    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove 
        Dim lHwnd As Int32 
        lHwnd = Me.Handle 
        If lHwnd = 0 Then Exit Sub 
        ReleaseCapture() 
        SendMessage(lHwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&) 
    End Sub 
End Class

No hay comentarios:

Publicar un comentario