ParentControlDesigner and adding controls using a Verb or during OnSetComponentDefaults.

  • Thread starter Thread starter Michel Theunissen
  • Start date Start date
M

Michel Theunissen

Hi,


I have implemented the basic skeleton for a WizardControl, which uses
a designer derived from ParentControlDesigner. The WizardControl has a
collection of type WizardPageCollection, derived from CollectionBase.
The collection is strongly typed using WizardPage objects (derived
from usercontrol).

The problem:
When I drop the WizardControl on a form, I can use the collection
editor to add WizardPages to the WizardControl. I catch the
"OnInserted" event from the collection, and then dynamically "Add" the
WizardPage to the "Controls" collection of the WizardControl, so I
synchronize the "WizardPagesCollection" with the WizardControl's
"Controls". This all goes fine, and after I am done with the
collection editor, I can select each single page and drop controls on
it. I can also move it to the back or bring each page to the front and
cycle through it.

However, when I use a Verb to add these WizardPages to the
WizardControl, I do see that the WizardPages are added to the control,
but I cannot select them. When I open the collection editor, I also
noticed that they have not been given a unique name, and I also
noticed that the "Design" category is missing in the properties of
these WizardPages inside the collection editor.
Also, when I add these pages using a "Verb", they are added to the
control, but when I close the form and reopen it all the pages have
disappeared. As if they were never persisted.

I am also not able to add a default WizardPage during the first time
the WizardControl is placed on a form. I used the
"OnSetComponentDefaults" overrideable function in the designer for
this, but again: a page is added, I can see it, but I cannot select
it, and when closing the designer and reopening, the page has
disappeared.

NOTE, everything works well if I use the CollectionEditor only.


*******************************************************************************
WizardControl class
*******************************************************************************
Namespace Controls

<Designer(GetType(WizardControlDesigner))> _
Public Class WizardControl
Inherits System.Windows.Forms.UserControl

'Wizard pages
Private WithEvents m_WizardPages As WizardPageCollection


<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
_
Public ReadOnly Property WizardPages() As WizardPageCollection
Get
Return m_WizardPages
End Get
End Property

Private Sub m_WizardPages_Inserted(ByVal sender As Object, ByVal e
As CommonApi.Classes.CEventCollectionArgs) Handles
m_WizardPages.Inserted
Dim NewPage As WizardPage = CType(e.NewValue, WizardPage)


'Add the control
Me.Panel_Pages.Controls.Add(CType(NewPage, Control))
End Sub

Private Sub m_WizardPages_Removed(ByVal sender As Object, ByVal e
As CommonApi.Classes.CEventCollectionArgs) Handles
m_WizardPages.Removed
Me.Controls.Remove(CType(e.NewValue, Control))
End Sub

End Class

End Namespace

*******************************************************************************
Designer class for the WizardControl
*******************************************************************************
Imports System.Windows.Forms.Design
Imports System.ComponentModel.Design

Imports CommonGui.Controls

Namespace Controls

Public Class WizardControlDesigner
Inherits ParentControlDesigner

Public Overrides Sub OnSetComponentDefaults()
MyBase.OnSetComponentDefaults()
End Sub

Public Overrides ReadOnly Property Verbs() As
System.ComponentModel.Design.DesignerVerbCollection
Get
If Verbs Is Nothing Then
Verbs = New DesignerVerbCollection
Dim Verb As DesignerVerb = New DesignerVerb("Add page",
New EventHandler(AddressOf _AddWelcomePage))

Verbs.Add(Verb)
End If

Return Verbs
End Get
End Property

Private Sub _AddWelcomePage(ByVal sender As Object, ByVal e As
EventArgs)
'Get control
Dim WizardControl As WizardControl = CType(Me.Component,
WizardControl)

'Create new wizard page
Dim WizardPage As WizardPage = New WizardPage

'Add wizard page
WizardControl.WizardPages.Add(WizardPage)
End Sub

End Class

End Namespace
*******************************************************************************
*******************************************************************************
*******************************************************************************



Any suggestions?
 
Back
Top