cs_jacques13
Messages postés252Date d'inscriptionmardi 3 juin 2003StatutMembreDernière intervention29 juin 2013
-
1 nov. 2008 à 21:12
jmfmarques
Messages postés7668Date d'inscriptionsamedi 5 novembre 2005StatutMembreDernière intervention22 août 2014
-
1 nov. 2008 à 22:32
Bonjour,
J'essaye de déplacer à la souris un Frame posé sur un PictureBox.
Après avoir fixé la propriété DragMode du contrôle à Automatic, je tente d'intercepter sa position avec le code suivant:
Private Sub FrameAjout_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then FrameAjout.Move FrameAjout.Left + X, FrameAjout.Top + Y
If FrameAjout.Left < 0 Then FrameAjout.Left = 0
If FrameAjout.Top < 0 Then FrameAjout.Top = 0
If FrameAjout.Left > Affi.ScaleWidth - FrameAjout.width Then FrameAjout.Left = Affi.ScaleWidth - FrameAjout.width
If FrameAjout.Top > Affi.ScaleHeight - FrameAjout.height Then FrameAjout.Top = Affi.ScaleHeight - FrameAjout.height
End Sub
Tant que le bouton gauche de la souris reste enfoncé, l'enveloppe du Frame se déplace correctement mais dès que je le relâche, le Frame vient se placer n'importe où, voire disparaît!
Quelqu'un voit-il la solution?
Merci
Jacques13
jmfmarques
Messages postés7668Date d'inscriptionsamedi 5 novembre 2005StatutMembreDernière intervention22 août 201427 1 nov. 2008 à 21:53
Bonjour,
et comme ceci, en laissant dans son coin la propréité Dragmode; dont nous n'avons pas besoin (donc = 0)?
Option Explicit
Dim MovTop, MovLft As Integer
Dim DbTop, DbLft As Integer
Private Sub FrameAjout_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then DbTop ScaleY(Y, 1, 3): DbLft ScaleX(X, 1, 3)
End If
End Sub
Private Sub FrameAjout_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
MovLft = Int((FrameAjout.Left + ScaleX(X, 1, 3)) - DbLft)
MovTop = Int((FrameAjout.Top + ScaleY(Y, 1, 3)) - DbTop)
FrameAjout.Move MovLft, MovTop
End If
End Sub