dotnet windows forms designtime:
hi!
i have a big problem with the designer in vs2003/c#. i searched the internet
but can't find any solution to the problem described below...
i would like to create a usercontrol with some content in it. e.g. a
titlebar and a stateicon and so on. there is also a panel (i'll name it
contentPanel) in the middle of the usercontrol (dockstyle.fill) where the
content should be added at design time. For this panel a created a public
property in the usercontrol so that you can access them from outside.
in some posts i've readed that's not possible to add other controls at
designtime to this contentPanel - so my idea was to write a custom designer
for the usercontrol which create a new panel on the rootform and than adding
it to the controls-list of the contentPanel.
until now - everything is nice :-)
the code and the usercontrol works as expected. i can add controls at
designtime to my contentpanel which lies inside the usercontrol.
but - and thats the problem - there's a little error-message in my job-list:
"Die Codegenerierung für die Eigenschaft 'Controls' ist fehlgeschlagen.
Fehler: 'Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.'"
in english: "code-generation for the property 'Controls' was failed: the
objectreference was not set on an objectinstance" (or something like that
:-))
here's a sample code:
[Designer(typeof(MyControlDesigner))]
public class MyUserControl : System.Windows.Forms.UserControl
{
// ... some code here
private Panel contentPanel;
public Panel ContentPanel
{
get { return this.contentPanel; }
}
}
public class MyControlDesigner : System.Windows.Forms.Design.ControlDesigner
{
public override void Initialize(IComponent component)
{
base.Initialize (component);
IDesignerHost designerHost =
(IDesignerHost)GetService(typeof(IDesignerHost));
// the designer create a new panel on the form
Panel panelInside = (Panel)designerHost.CreateComponent(typeof(Panel));
((MyUserControl)this.Control).ContentPanel.Controls.Add(panel);
}
}
it would be great if someone could help!
--------------------------------
From: André Kroll