Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 如何通过DragandDrop只知道接口传递对象?_.net_Vb.net_Drag And Drop - Fatal编程技术网

.net 如何通过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

有很多东西 实现一个接口 如何在只知道用户界面的情况下通过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 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运算符查看它是否实现了接口