Option Strict On Public Class Form1 Dim ptO As Point Private Sub Panel1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown If e.Button = Windows.Forms.MouseButtons.Left Then 'mémorisation de la position du clic gauche ptO = Point.Add( _ New Point(e.X + SystemInformation.FrameBorderSize.Width, _ e.Y + SystemInformation.FrameBorderSize.Height + SystemInformation.CaptionHeight), _ New Size(DirectCast(sender, Panel).Location)) End If End Sub Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove If e.Button = Windows.Forms.MouseButtons.Left Then 'déplacement du formulaire en se servant de la position du curseur Me.Location = Point.Subtract(Cursor.Position, New Size(ptO)) End If End Sub End Class
ptO = Point.Add(New Point(e.X, e.Y), New Size(DirectCast(sender, Panel).Location))
Option Explicit On Public Class Form1 Private dernierpoint As Point Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown If e.Button Windows.Forms.MouseButtons.Left Then dernierpoint New Point(e.X, e.Y) End Sub Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove If e.Button <> Windows.Forms.MouseButtons.Left Then Exit Sub Left = Left + (e.X - dernierpoint.X) Top = Top + (e.Y - dernierpoint.Y) End Sub End Class
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question