Je suis tout nouveau à VB- dans le code suivant, j'ai cette erreur. La clause Handles nécessite une variable WithEvents définie dans le type conteneur ou l'un de ses types de base. (BC30506)MouseDown sur l'erreur Picturebox: clause Handles nécessite un WithEvents
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
Fondamentalement, je suis en train de déplacer un objet zone d'image avec l'événement mousedown selon cet extrait
Private Offset As Size 'used to hold the distance of the mouse`s X and Y position to the picturebox Left and Top postition
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
Dim ptc As Point = Me.PointToClient(MousePosition) 'get the mouse position in client coordinates
Offset.Width = ptc.X - PictureBox1.Left 'get the width distance of the mouse X position to the picturebox`s Left position
Offset.Height = ptc.Y - PictureBox1.Top 'get the height distance of the mouse Y position to the picturebox`s Top position
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 'make sure the left mouse button is down first
Dim ptc As Point = Me.PointToClient(MousePosition) 'get the mouse position in client coordinates
PictureBox1.Left = ptc.X - Offset.Width 'set the Left position of picturebox to the mouse position - the offset width distance
PictureBox1.Top = ptc.Y - Offset.Height 'set the Top position of picturebox to the mouse position - the offset height distance
End If
End Sub
J'ai lu les questions et ne peut pas sembler saisir exactement pourquoi cette le code ne fonctionne pas.
Vous avez créé le PictureBox en code, n'est-ce pas? – Plutonix