What I want to do is have the ability to drag a form object into a panel to add that form into the panels controls. What I have is a base class for my form called "DForm" and any other type of form that will have this drag/drop ability will be a child of it. I have another form that has a panel inside which accepts the drag/drop event and adds that form into its controls (a form inside a panel). My issue is that when I try to pass the DForm object when calling the DoDragDrop() function it is of the child DForm object and not of DForm. So I cannot do the drop unless I specify the specific child type and not just the base/parent type. Below is a shortened version better explaining my issue.
Base Class:
Child form:
Main form that allows a drop: The issue is in this form when dragdropping
So when I drag a SomeChildForm object into the panel it is of that type (obviously) and not of type DForm. Because I have multiple classes which inherit DForm I need to be able to take any class that is or inherits DForm. How can I 'fix' this issue?
Base Class:
VB.NET:
Public Class DForm
Inherits Form
Private Sub dragform() Handles Me.MouseDown
If TopLevel Then
DoDragDrop(Me, DragDropEffects.Move)
End If
End Sub
End Class
Child form:
VB.NET:
Public Class SomeChildForm
Inherits DForm
'other code not shown
End Class
Main form that allows a drop: The issue is in this form when dragdropping
VB.NET:
Public Class MasterForm
Inherits Form
Private WithEvents formcontainer As New Panel With {.Dock = DockStyle.Fill, .AllowDrop = True}
Public Sub New()
Me.Controls.Add(formcontainer)
End Sub
Private Sub containerdragenter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles formcontainer.DragEnter
If (e.Data.GetDataPresent(GetType(DForm))) Then
e.Effect = DragDropEffects.Move
End If
End Sub
Private Sub containerdragdrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles formcontainer.DragDrop
If e.Data.GetDataPresent(GetType(DForm)) Then 'WHEN "SomeChildForm" IS DROPPED, IT IS OF TYPE "SomeChildForm" AND NOT DForm. How do I fix this?
'cast object as DForm then add it into formcontainer.controls
MsgBox("added")
End If
End Sub
End Class
So when I drag a SomeChildForm object into the panel it is of that type (obviously) and not of type DForm. Because I have multiple classes which inherit DForm I need to be able to take any class that is or inherits DForm. How can I 'fix' this issue?