问题描述:

i have 2 panel in my Control.

panel 3 added to panel 1 for Title ,

panel 2 added to panel 1 For Content &

panel 1 is My Control

i do create this Control For my Project .

this Control Code :

public class ControWithTitle : Panel // Panel 1

{

public Panel Title = new Panel { Dock = DockStyle.Top, Height = 20, BackColor = Color.Black }; // Panel 2

public Panel Content = new Panel { Dock = DockStyle.Fill, BackColor = Color.White }; // Panel 3

public ControWithTitle ()

: base()

{

this.Controls.Add(Title);

this.Controls.Add(Content);

}

}

i do When Add This control in Form > Create Design Mode For Content . not panel 1 Or Title Paenl....

this Code not Work ... All Panel is Lock . after Build Project , every Changed was reset...

is work this true ? please help me to Create This. Thanks

 ╔═══════════╗ < Paenl 1

║╔═════════╗║

║║ Panel 2 ║║

║╚═════════╝║

║╔═════════╗║

║║ ║║

║║ ║║

║║ ║║

║║ Panel 3 ║║ < Design Mode For This Paenl

║║ ║║

║║ ║║

║║ ║║

║╚═════════╝║

╚═══════════╝

after pasted Dear @King's Code My Problem Not Solved...

This Error has in my project :

this is my Code for a Other Sample After (@Hans Passant & @King King) Answer :

 [Designer(typeof(CustomDesigner))]

public partial class ControlWithTitle : UserControl // Panel 1

{

private System.ComponentModel.IContainer components = null;

private ListView listView1 = new ListView();

protected override void Dispose (bool disposing)

{

if (disposing && (components != null)) { components.Dispose(); }

base.Dispose(disposing);

}

private void InitializeComponent ()

{

components = new System.ComponentModel.Container();

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

this.Controls.Add(listView1);

}

public Panel Title = new Panel { };

public Panel Content = new Panel { };

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

public ListView Employees { get { return listView1; } }

public ControlWithTitle ()

{

InitializeComponent();

}

}

public class CustomDesigner : ParentControlDesigner

{

public override void Initialize (IComponent component)

{

ControlWithTitle control = Control as ControlWithTitle;

if (control != null)

{

EnableDesignMode(control.Employees, "Employees");

}

}

}

网友答案:

You can try this code, you have to add reference to the System.Design.dll and using System.Windows.Forms.Design;:

[Desiner(typeof(CustomDesigner))]
public class ControWithTitle : Panel // Panel 1
{
   //....
}
public class CustomDesigner : ParentControlDesigner {
   public override void Initialize(IComponent component){
      ControWithTitle control = Control as ControWithTitle;
      if(control != null){
        //Enable designmode for Panel3
        EnableDesignMode(control.Content, "Content");
      }
   }
}
相关阅读:
Top