Ce bout de code permet lors du Drag and Drop de faire suivre l'image pendant le déplacement
Private ancX As Integer, ancY As Integer, origx As Integer, origy As Integer
Private harponne As Boolean
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.Left = X
Text1.Top = Y
End Sub
Private Sub Text1_Mousedown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ancX = X
ancY = Y
harponne = True
If Not Text1.Container Is Picture1 Then
origx = Text1.Left
origy = Text1.Top
End If
End Sub
Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If harponne Then
Text1.Left = Text1.Left + (X - ancX)
Text1.Top = Text1.Top + (Y - ancY)
End If
End Sub
Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If harponne And Not Text1.Container Is Picture1 Then
If Text1.Left >= Picture1.Left And Text1.Top >= Picture1.Top And _
Text1.Left <= Picture1.Width + Picture1.Left And Text1.Top <= Picture1.Top + Picture1.Height Then
Text1.Left = 0
Text1.Top = 0
Set Text1.Container = Picture1
MsgBox "voilà ton contrôle sur le plateau" & vbCrLf & "place-l'y maintenant où tu veux"
Else
Text1.Left = origx
Text1.Top = origy
End If
End If
harponne = False
End Sub
Text1.Left = Text1.Left - Picture1.Left
Text1.Top = Text1.Top - Picture1.Top
Private Sub Text1_DblClick()
If Text1.Container Is Picture1 Then
If MsgBox("voules-vous annuler ce placement ?", vbYesNo) = vbYes Then
Set Text1.Container = Me
Text1.Left = origx
Text1.Top = origy
End If
End If
End Sub
Private ancX As Integer, ancY As Integer, origx As Integer, origy As Integer
Private harponne As Boolean
Private Sub Text1_DblClick()
If Text1.Container Is Picture1 Then
If MsgBox("voules-vous annuler ce placement", vbYesNo) = vbYes Then
remettre Text1
End If
End If
End Sub
Private Sub Text1_Mousedown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ancX = X
ancY = Y
If Not Text1.Container Is Picture1 Then
origx = Text1.Left
origy = Text1.Top
End If
harponne = True
End Sub
Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If harponne Then
Text1.Left = Text1.Left + (X - ancX)
Text1.Top = Text1.Top + (Y - ancY)
If Not Text1.Container Is Picture1 Then
If harponne And Not Text1.Container Is Picture1 Then
If Text1.Left >= Picture1.Left And Text1.Top >= Picture1.Top And _
Text1.Left <= Picture1.Width + Picture1.Left And Text1.Top <= Picture1.Top + Picture1.Height Then
Text1.Left = Text1.Left - Picture1.Left
Text1.Top = Text1.Top - Picture1.Top
Set Text1.Container = Picture1
End If
End If
Else
Select Case Text1.Left
Case Is < 0
Text1.Left = 1
Case Is > Picture1.Width - Text1.Width
Text1.Left = Picture1.Width - Text1.Width - 1
End Select
Select Case Text1.Top
Case Is < 0
Text1.Top = 1
Case Is > Picture1.Height - Text1.Height
Text1.Top = Picture1.Height - Text1.Height - 1
End Select
End If
End If
End Sub
Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not Text1.Container Is Picture1 Then
remettre Text1
End If
harponne = False
End Sub
Private Sub remettre(ctrl As TextBox)
Set Text1.Container = Me
Text1.Left = origx
Text1.Top = origy
End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionSerai-ce le fait de créer un New Bitmap et un New Cursor et que ceux-ci ne seraient pas "détruits" à la fin du Drag and Drop ?
Private Sub CasesabotMousedown(sender As Object, e As MouseEventArgs)
sourceindex = Convert.ToInt32(DirectCast(sender, PictureBox).Name.Substring(9))
source = DirectCast(sender, PictureBox).Name.Substring(0, 9)
ancX = e.X
ancY = e.Y
harponne = True
origx = pictsabot(sourceindex).Left
origy = pictsabot(sourceindex).Top
pictsabot(sourceindex).BringToFront()
End Sub
Private Sub CasesabotMouseMove(sender As Object, e As MouseEventArgs)
If harponne = True Then
pictsabot(sourceindex).Left = pictsabot(sourceindex).Left + (e.X - ancX)
pictsabot(sourceindex).Top = pictsabot(sourceindex).Top + (e.Y - ancY)
End If
End Sub
Private Sub CasesabotMouseUp(sender As Object, e As MouseEventArgs)
Dim colonnedrag As Integer, lignedrag As Integer
Dim positionmouse As Point
If harponne = True Then
positionmouse = Me.PointToClient(Cursor.Position) ' position du curseur sur la Form
' chaque case fait 34 de haut et de large
' on enlève la position de la case en haut à gauche et on divise par 34 pour avoir la colonne ou la ligne de la case
colonnedrag = (positionmouse.X - 205) \ 34
lignedrag = (positionmouse.Y - 60) \ 34
If colonnedrag >= 0 AndAlso lignedrag >= 0 Then
pictsabot(sourceindex).Left = origx
pictsabot(sourceindex).Top = origy
' Getindex me donne l'indice de la case en fonction de la ligne et de la colonne
destinationindex = Getindex(lignedrag, colonnedrag)
CasejeuDrop()
End If
End If
harponne = False
End Sub