Ok I have been working on this idea of a control that I have. I want the control to be able to add other controls to the form that it is on at design time. I am having a hell of a time trying to figure this out. I decided if nothing else I will just serialize to the code behind file myself. The only issue is I can't seem to get the location of the code behind file. I have only been able to get the location of the solution. I want to at least get the directory of the project before I go reading the files to see if it is the correct one. Anyways here is my code if there is another better way to do this.
<Designer(GetType(PanelManagerControlDesigner))> _
Public Class DynamicViewControl
Inherits System.Windows.Forms.Panel
End Class
Public Class PanelManagerControlDesigner
Inherits System.Windows.Forms.Design.ControlDesigner
Public _Control As DynamicViewControl
Public Overrides Sub Initialize(ByVal component As System.ComponentModel.IComponent)
MyBase.Initialize(component)
_Control = Me.Control
End Sub
Public Overrides ReadOnly Property ActionLists() As System.ComponentModel.Design.DesignerActionListCollection
Get
Dim d As New System.ComponentModel.Design.DesignerActionListCollection()
d.Add(New PanelManagerControlDesignerActionList(Me))
Return d
End Get
End Property
End Class
Public Class PanelManagerControlDesignerActionList
Inherits System.ComponentModel.Design.DesignerActionList
Dim _controlDesigner As PanelManagerControlDesigner
Dim _designerActionUISvc As System.ComponentModel.Design.DesignerActionUIService
Dim _Control As DynamicViewControl
Public Sub New(ByVal designer As PanelManagerControlDesigner)
MyBase.New(designer.Component)
_designerActionUISvc = GetService(GetType(System.ComponentModel.Design.DesignerActionUIService))
_controlDesigner = designer
_Control = designer._Control
End Sub
Private Sub AddPanel()
Dim p As New Panel()
Dim i As Integer = 0
'*****I NEED TO WRITE TO THE CODE BEHIND FILE RIGHT HERE********
End Sub
Public Overrides Function GetSortedActionItems() As System.ComponentModel.Design.DesignerActionItemCollection
Dim items As New System.ComponentModel.Design.DesignerActionItemCollection()
Dim mi As New System.ComponentModel.Design.DesignerActionMethodItem(Me, "AddPanel", "Add Panel", "Methods")
items.Add(mi)
Return items
End Function
End Class