I have been developing some custom smart tags. I am using a DesignerActionMethodItem which gets me to a fired method in code. When I try to hit the controls.Add the control is added but it seems the designer is unaware of it. It is never serialized and it goes away when the form is refreshed in the designer. Any help would be greatly appreciated. I am sort of stuck and google hasn't helped me. Please don't send me anything about smart tags that has nothing to do with adding controls dynamically at design time, I have already read so many looking for this.
A:
here is slimmed down version of my code:
Imports System.ComponentModel Imports System.Windows.Forms
_ Public Class Example
End Class
Public Class ExampleControlDesigner Inherits System.Windows.Forms.Design.ControlDesigner
Public _Control As Example
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 ExampleControlDesignerActionList(Me))
Return d
End Get
End Property
End Class
Public Class ExampleControlDesignerActionList Inherits System.ComponentModel.Design.DesignerActionList
Dim _controlDesigner As ExampleControlDesigner
Dim _designerActionUISvc As System.ComponentModel.Design.DesignerActionUIService
Dim _Control As Example
Public Sub New(ByVal designer As ExampleControlDesigner)
MyBase.New(designer.Component)
_designerActionUISvc = GetService(GetType(System.ComponentModel.Design.DesignerActionUIService))
_controlDesigner = designer
_Control = designer._Control
End Sub
Public Sub AddControl()
Dim frm As Form = _Control.Parent
Dim b As New Button
frm.Controls.Add(b)
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, "AddControl", "Add Control", "Methods")
items.Add(mi)
Return items
End Function
End Class
The problem occurs inside the AddControl method. Because this code is being executed at design time it does not behave as intended. A control is added to the form, but it is never seriallized and therefore can not be interacted with. Any help would be greatly appreciated.