Windows Develop Bookmark and Share   
 index > Windows Forms Designer > child controls of custom control disappear at run-time
 

child controls of custom control disappear at run-time

Hi!

I'm developing custom control with two panels. I'll make just onlyone panel have controls.

so, I used 'EnableDesignMode'. below is my code

[Designer(typeof(WPCTest.WPCTestDesigner))]
public partial class WPCTest : UserControl
{
public Panel Area { get { return this.panel2; } }

internal class WPCTestDesigner : ParentControlDesigner
{
public override void Initialize(IComponent component)
{
base.Initialize(component);

EnableDesignMode(((WPCTest)component).Area, "Area");
}
}
}

In Designer, user can design Form using custom control (for example, I added a Button into custom control).but, at run-time, the child controls of the custom control disappear.

so, I saw the generated code written by Windows Form Designer.

then, I found the factthat thechild controlswere generated but were not added into the ControlCollection of custom control.

below is the the generated code written by Windows Form Designer.

this.wpcTest1 = new WPCTest();
this.button1 = new System.Windows.Forms.Button();
// wpcTest1
//
this.wpcTest1.Location = new System.Drawing.Point(51, 23);
this.wpcTest1.Name = "wpcTest1";
this.wpcTest1.Size = new System.Drawing.Size(150, 150);
this.wpcTest1.TabIndex = 0;

I have never developed custom control. so, I have no idea about how to fix this problem.

Please help me.

sangminny  Friday, June 09, 2006 9:31 AM

I found a article. (http://blogs.msdn.com/subhagpo/archive/2005/03/21/399782.aspx)

the article says to add the attribute on the property (Area) that tells the code generator to write out code for the value contanised in this property.

so, add this attribute on Area property

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

public Panel Area { get { return this.panel2; } }

 

it works well.

thanks

sangminny  Monday, June 12, 2006 2:53 AM

I found a article. (http://blogs.msdn.com/subhagpo/archive/2005/03/21/399782.aspx)

the article says to add the attribute on the property (Area) that tells the code generator to write out code for the value contanised in this property.

so, add this attribute on Area property

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

public Panel Area { get { return this.panel2; } }

 

it works well.

thanks

sangminny  Monday, June 12, 2006 2:53 AM

You can use google to search for other answers

Custom Search

More Threads

• Controls emulating Mac interface
• User Control + URI formats are not supported
• Error while trying to create a form.
• Visual Designer crash - could not find KB article
• 'Resources.Resources' error unable to open form in designer mode
• default values for inherited control
• how to add childmenu in designer contextmenu
• Setting DesignerLoader.LoaderHost.RootComponent to an existing Control
• UITypeEditor should create file in project directory
• draw subscript superscript in the datagridview header