Public Class Form1 Dim NewPoint As New System.Drawing.Point() Dim X, Y As Integer Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown X = Control.MousePosition.X - Me.Location.X Y = Control.MousePosition.Y - Me.Location.Y End Sub Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove If e.Button = MouseButtons.Left Then NewPoint = Control.MousePosition NewPoint.X -= (X) NewPoint.Y -= (Y) Me.Location = NewPoint End If End Sub End Class
Public Const HTCAPTION As Integer = 2 Public Const WM_NCLBUTTONDOWN As Integer = 161 <DllImport("user32.dll", EntryPoint:="SendMessageA")> _ Public Shared Function SendMessage(ByVal hwnd As Integer, _ ByVal wMsg As Integer, _ ByVal wParam As Integer, _ ByRef lParam As Integer) As Integer End Function <DllImport("user32.dll")> _ Public Shared Function ReleaseCapture() As Integer End Function Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown If e.Button = Windows.Forms.MouseButtons.Left And Me.WindowState <> FormWindowState.Maximized Then ReleaseCapture() SendMessage(Me.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0) End If End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove Dim a As PictureBox = PictureBox1 If e.Button Forms.MouseButtons.Left And a.MouseButtons.Left Forms.MouseButtons.Left Then Me.Left = e.X Me.Top = e.Y End If Me.Dispose() End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove Dim a As MouseEventArgs = PictureBox1.MouseDown If e.Button Forms.MouseButtons.Left And a.Button Forms.MouseButtons.Left Then Me.Left = e.X Me.Top = e.Y End If Me.Dispose() End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove If e.Button Forms.MouseButtons.Left And bDOWN True Then Me.Left = e.X Me.Top = e.Y End If End Sub Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown bDOWN = True End Sub Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp bDOWN = False End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove If e.Button Forms.MouseButtons.Left And bDOWN True Then Me.Left = Me.Left + (e.X - Me.Left) Me.Top = Me.Top + (e.Y - Me.Top) End If End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp Dim b As System.Drawing.Point Dim a As System.Drawing.Rectangle Dim cH, cW As Integer a = Screen.PrimaryScreen.WorkingArea cH = Me.Size.Height - Me.Left cW = Me.Size.Width - Me.Top b.X = e.X b.Y = e.Y b.X = cH + b.X b.Y = cW + b.Y If bDOWN = True Then Me.Top = a.Y Me.Left = a.X bDOWN = False End If End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp Dim b As System.Drawing.Point Dim a As System.Drawing.Rectangle Dim cH, cW As Integer a = Screen.PrimaryScreen.WorkingArea cH = a.Height - Me.Size.Height cW = a.Width - Me.Size.Width b.X = e.X b.Y = e.Y If bDOWN = True Then Me.Top = (cH - Me.Top) + b.Y Me.Left = cW - Me.Left bDOWN = False End If End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove mod_form.OBJ_MouseMove(MAIN_Accueil.ActiveForm, e) End Sub Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown mod_form.OBJ_MouseDown(e) End Sub Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp mod_form.OBJ_MouseUp(e) End Sub
Module mod_form Private iX, iY As Integer Private bDOWN As Boolean = False Public Sub OBJ_MouseMove(ByVal FormToMove As Form, ByVal e As System.Windows.Forms.MouseEventArgs) If e.Button = Forms.MouseButtons.Left Then FormToMove.Left = e.X - iX + FormToMove.Left FormToMove.Top = e.Y - iY + FormToMove.Top End If End Sub Public Sub OBJ_MouseDown(ByVal e As System.Windows.Forms.MouseEventArgs) bDOWN = True iY = e.Y iX = e.X End Sub Public Sub OBJ_MouseUp(ByVal e As System.Windows.Forms.MouseEventArgs) bDOWN = False End Sub End Module