Ok, I tried it the way you said, but still can't get it working. I'm doing
this in VB.Net btw. I ran the code you sent and it worked fine, but when I
tried to get mine working the same way, I'm still having problems. Mainly,
the target form isn't recognizing the object that is being dragged. I'm not
sure exactly what I'm doing wrong. I'm posting the relevant parts of my
code. Think you can help?
Private Sub lbT1Systems_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lbT1Systems.MouseDown
If e.Button = MouseButtons.Left Then
If lbT1Systems.SelectedIndex > -1 Then
Dim obj As ManagedObject =
lbT1Systems.Items(lbT1Systems.SelectedIndex)
Debug.WriteLine("Dragging object: " & obj.Name)
lbT1Systems.DoDragDrop(obj, DragDropEffects.Copy)
End If
End If
End Sub
Private Sub ViewsForm_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles MyBase.DragEnter
If (e.Data.GetDataPresent(GetType(ManagedObject))) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub ViewsForm_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles MyBase.DragDrop
Dim obj As ManagedObject =
CType(e.Data.GetData(GetType(ManagedObject)), ManagedObject)
Debug.WriteLine("Object dropped: " & obj.Name)
colMObj.Add(obj)
End Sub
<Serializable()> _
Public Class ManagedObject
Inherits Object
Protected _Name As String
Protected _ManagedType As String
Protected _Info As String
Protected _Location As Point
Protected _Size As Size
Protected _Relationships As New RelationCollection
Public Property Name()
Get
Return _Name
End Get
Set(ByVal Value)
_Name = Value
SetInfo()
End Set
End Property
Public Property ManagedType() As String
Get
Return _ManagedType
End Get
Set(ByVal Value As String)
_ManagedType = Value
SetInfo()
End Set
End Property
Public ReadOnly Property Info() As String
Get
Return _Info
End Get
End Property
Public Property Relationships() As RelationCollection
Get
Return _Relationships
End Get
Set(ByVal Value As RelationCollection)
_Relationships = Value
End Set
End Property
Public Property Location() As Point
Get
Return _Location
End Get
Set(ByVal Value As Point)
_Location = Value
End Set
End Property
Public Property Size() As Size
Get
Return _Size
End Get
Set(ByVal Value As Size)
_Size = Value
End Set
End Property
Protected Overridable Sub SetInfo()
_Info = _Name
End Sub
Public Overrides Function ToString() As String
Return _Name
End Function
End Class