首先自定义数据类型:类:
Private Class AppDMClassClass AppDMClass
Private MyAppName As String
Private MyAppPath As String
Public Sub New()Sub New()
End Sub
Public Sub New()Sub New(ByVal Name As String, ByVal Path As String)
MyAppName = Name
MyAppPath = Path
End Sub
Public Property Name()Property Name() As String
Get
Return MyAppName
End Get
Set(ByVal value As String)
MyAppName = value
End Set
End Property
Public Property Path()Property Path() As String
Get
Return MyAppPath
End Get
Set(ByVal value As String)
MyAppPath = value
End Set
End Property
End Class
在一个ListBox中已经加载有AppDMClass类型是数据:
Private Sub LoadXml2List()Sub LoadXml2List(ByVal XmlFilePath As String)
XmlDoc = New XmlDocument
XmlDoc.Load(XmlFilePath)
Root = XmlDoc.SelectSingleNode("AppList")
NodeList = Root.ChildNodes
AppList.Clear()
If NodeList.Count > 0 Then
For Each Node In NodeList
AppList.Add(New AppDMClass(Node.FirstChild.InnerText, Node.LastChild.InnerText))
'Node.ChildNodes(0).InnerText '当只有两个节点=node.FirstChild.InnerText
'Node.ChildNodes(1).InnerText '可以等于=node.LastChild .InnerText
Next
BindData2List()
End If
End Sub
Private Sub BindData2List()Sub BindData2List()
Me.ListBoxAPP.DataSource = Nothing
Me.ListBoxAPP.DataSource = AppList
Me.ListBoxAPP.DisplayMember = "Name"
Me.ListBoxAPP.ValueMember = "Path"
End Sub
启动拖放数据:在拖放过程中传送自定义类型数据:AppDMClass。
Private Sub ListBoxAPP_MouseMove()Sub ListBoxAPP_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBoxAPP.MouseMove
If Me.ListBoxAPP.SelectedIndex > -1 Then
Dim DM As AppDMClass
DM = CType(AppList.Item(Me.ListBoxAPP.SelectedIndex), AppDMClass)
Me.ListBoxAPP.DoDragDrop(DM, DragDropEffects.Copy)
End If
End Sub
最后对拖放数据进行操作:注意接收对象:BtStartApp(一个按钮)的AllowDrop设置为True。
Private Sub BtStartApp_DragDrop()Sub BtStartApp_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles BtStartApp.DragDrop
If e.Data.GetDataPresent(GetType(AppDMClass)) Then
Dim DM As AppDMClass = e.Data.GetData(GetType(AppDMClass))
System.Diagnostics.Process.Start(DM.Path)
'处理拖放进来的数据。
End If
End Sub
Private Sub BtStartApp_DragEnter()Sub BtStartApp_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles BtStartApp.DragEnter
If e.Data.GetDataPresent(GetType(AppDMClass)) Then
'启动拖放效果。
e.Effect = DragDropEffects.Copy
End If
End Sub
程序界面:【拖放操作过程,选中聊天QQ,按住鼠标左键,拖到 启动程序按钮 上放开,就会自动运行QQ程序了。】
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/linjimu/archive/2008/01/18/2051677.aspx