quentin0590
Messages postés46Date d'inscriptionmardi 20 juillet 2004StatutMembreDernière intervention31 juillet 2009
-
1 avril 2009 à 20:53
quentin0590
Messages postés46Date d'inscriptionmardi 20 juillet 2004StatutMembreDernière intervention31 juillet 2009
-
2 avril 2009 à 22:13
Bonjour à tous, je ne sais pas trop dans quelle catégorie mettre ce post... IL ira dans général
Voilà mon problème. Je cherchai à faire du drag and drop d'un picture box a un autre. J'ai touvé chez nos amis du msdn ce code qui marche plutot bien.
Public Class Form2
Dim m_MouseIsDown As Boolean
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.S2_1_2.AllowDrop = True
Me.S2_1_1.AllowDrop = True
Me.S2_1_3.AllowDrop = True
Me.S2_1_4.AllowDrop = True
End Sub
#Region "Mouse Down"
Private Sub S2_1_1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles S2_1_1.MouseDown
If Not S2_1_1.Image Is Nothing Then
m_MouseIsDown = True
End If
End Sub
Private Sub S2_1_2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles S2_1_2.MouseDown
If Not S2_1_2.Image Is Nothing Then
m_MouseIsDown = True
End If
End Sub
Private Sub S2_1_3_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles S2_1_3.MouseDown
If Not S2_1_3.Image Is Nothing Then
m_MouseIsDown = True
End If
End Sub
Private Sub S2_1_4_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles S2_1_4.MouseDown
If Not S2_1_4.Image Is Nothing Then
m_MouseIsDown = True
End If
End Sub
#End Region
#Region "Mouse Move"
Private Sub S2_1_1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles S2_1_1.MouseMove
If m_MouseIsDown = True Then
S2_1_1.DoDragDrop(S2_1_1.Image, DragDropEffects.Copy Or DragDropEffects.Move)
End If
m_MouseIsDown = False
End Sub
Private Sub S2_1_2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles S2_1_2.MouseMove
If m_MouseIsDown = True Then
S2_1_2.DoDragDrop(S2_1_2.Image, DragDropEffects.Copy Or DragDropEffects.Move)
End If
m_MouseIsDown = False
End Sub
Private Sub S2_1_3_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles S2_1_3.MouseMove
If m_MouseIsDown = True Then
S2_1_3.DoDragDrop(S2_1_3.Image, DragDropEffects.Copy Or DragDropEffects.Move)
End If
m_MouseIsDown = False
End Sub
Private Sub S2_1_4_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles S2_1_4.MouseMove
If m_MouseIsDown = True Then
S2_1_4.DoDragDrop(S2_1_4.Image, DragDropEffects.Copy Or DragDropEffects.Move)
End If
m_MouseIsDown = False
End Sub
#End Region
#Region "DragEnter"
Private Sub S2_1_1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles S2_1_1.DragEnter
If e.Data.GetDataPresent(DataFormats.Bitmap) Then
If e.KeyState = 9 Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.Move
End If
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub S2_1_2_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles S2_1_2.DragEnter
If e.Data.GetDataPresent(DataFormats.Bitmap) Then
If e.KeyState = 9 Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.Move
End If
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub S2_1_3_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles S2_1_3.DragEnter
If e.Data.GetDataPresent(DataFormats.Bitmap) Then
If e.KeyState = 9 Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.Move
End If
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub S2_1_4_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles S2_1_4.DragEnter
If e.Data.GetDataPresent(DataFormats.Bitmap) Then
If e.KeyState = 9 Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.Move
End If
Else
e.Effect = DragDropEffects.None
End If
End Sub
#End Region
#Region "DragDrop"
Private Sub S2_1_2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles S2_1_2.DragDrop
S2_1_2.Image = e.Data.GetData(DataFormats.Bitmap)
End Sub
Private Sub S2_1_1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles S2_1_1.DragDrop
S2_1_1.Image = e.Data.GetData(DataFormats.Bitmap)
End Sub
Private Sub S2_1_3_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles S2_1_3.DragDrop
S2_1_3.Image = e.Data.GetData(DataFormats.Bitmap)
End Sub
Private Sub S2_1_4_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles S2_1_4.DragDrop
S2_1_4.Image = e.Data.GetData(DataFormats.Bitmap)
End Sub
#End Region
End Class
Cependant je suis obliger de déclaré les evenement pr chaque picture, il y en as plus de 50 ^^.
Est il possible de generaliser la code pr tout les picture box ?
cs_Malkuth
Messages postés268Date d'inscriptionsamedi 22 février 2003StatutMembreDernière intervention24 avril 20134 2 avril 2009 à 11:38
je trouve ca un peu "hard comme solution l'héritage alors que sender a été prévu pile pour se genre de cas a moins que tu doive en faire un control élaboré et réutilisé fréquement
quentin0590
Messages postés46Date d'inscriptionmardi 20 juillet 2004StatutMembreDernière intervention31 juillet 2009 2 avril 2009 à 22:13
Cela me donne donc (en quelques lignes ^^)
<hr size="2" width="100%" />
#Region "Mouse Down"
Private Sub Mouse_Down(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles S2_1_1.MouseDown, S2_1_2.MouseDown, S2_1_3.MouseDown, S2_1_4.MouseDown
If Not sender.Image Is Nothing Then
m_MouseIsDown = True
End If
End Sub
#End Region
<hr size="2" width="100%" />
#Region "Mouse Move"
Private Sub Mouse_Move(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles S2_1_1.MouseMove, S2_1_2.MouseMove, S2_1_3.MouseMove, S2_1_4.MouseMove
If m_MouseIsDown = True Then
sender.DoDragDrop(sender.Image, DragDropEffects.Copy Or DragDropEffects.Move)
End If
m_MouseIsDown = False
End Sub
#End Region
<hr size="2" width="100%" />#Region "DragEnter"
Private Sub Drag_Enter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles S2_1_1.DragEnter, S2_1_2.DragEnter, S2_1_3.DragEnter, S2_1_4.DragEnter
If e.Data.GetDataPresent(DataFormats.Bitmap) Then
If e.KeyState = 9 Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.Move
End If
Else
e.Effect = DragDropEffects.None
End If
End Sub
#End Region
<hr size="2" width="100%" />#Region "DragDrop"
Private Sub Drag_Drop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles S2_1_1.DragDrop, S2_1_2.DragDrop, S2_1_3.DragDrop, S2_1_4.DragDrop
sender.Image = e.Data.GetData(DataFormats.Bitmap)
End Sub
#End Region
<hr size="2" width="100%" />
Merci beaucoup, ça change la vie ce sender. Plus besoin de faire 36 ligne de codes qui diffères que d'un objet