.net 如何通过DragandDrop只知道接口传递对象?
有很多东西 实现一个接口 如何在只知道用户界面的情况下通过DragandDrop传递对象.net 如何通过DragandDrop只知道接口传递对象?,.net,vb.net,drag-and-drop,.net,Vb.net,Drag And Drop,有很多东西 实现一个接口 如何在只知道用户界面的情况下通过DragandDrop传递对象 Public Class test_1 Implements I_NAME Public Property Name As String Implements I_NAME.Name End Class Public Class WPF_TEST Private Sub txt_drop_source_MouseDown(sender As Object, e As MouseButto
Public Class test_1
Implements I_NAME
Public Property Name As String Implements I_NAME.Name
End Class
Public Class WPF_TEST
Private Sub txt_drop_source_MouseDown(sender As Object, e As MouseButtonEventArgs) Handles txt_drop_source.MouseDown
Dim obj As New test_1
DragDrop.DoDragDrop(Me, obj, DragDropEffects.All)
End Sub
Private Sub txt_drop_DragEnter(sender As Object, e As DragEventArgs) Handles txt_drop.DragEnter
If e.Data.GetDataPresent(GetType(I_NAME)) Then
e.Effects = DragDropEffects.All
End If
End Sub
Private Sub txt_drop_Drop(sender As Object, e As DragEventArgs) Handles txt_drop.Drop
Dim obj As Object = e.Data.GetData(GetType(I_NAME))
If IsNothing(obj) = False Then
MsgBox(obj.ToString)
End If
End Sub
End Class此处不能使用GetDataPresent(),因为您不知道类的名称。因此,实际调用GetData()并使用is运算符查看它是否实现了接口