1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
Public Class Form2
Public Sub New()
' Cet appel est requis par le concepteur.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
'ces 3 buttons autorise un drop par dessus
Button1.AllowDrop = True
Button2.AllowDrop = True
Button3.AllowDrop = True
'celui la non (par defaut je l'ai mis comme exemple)
Button4.AllowDrop = False
End Sub
'action dragenter :effet c'est une copy
'on regroupe les handlers des 3 premiers buttons cooperative
Private Sub Button1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Button1.DragEnter, Button2.DragEnter, Button3.DragEnter
If (e.Data.GetDataPresent(DataFormats.Text)) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
' l'action dragfrop:ici copie proprement dite
' idem pour la cooperative des handlers
Private Sub Button1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Button1.DragDrop, Button2.DragDrop, Button3.DragDrop
Dim destBtn As Button = CType(sender, Button)
destBtn.BackColor = Color.FromName(e.Data.GetData(DataFormats.Text).ToString)
End Sub
End Class |
Partager