0

コントロールに 2 つのパネルがあります。

Title の panel 1 に panel 3 を追加、 content の panel 1 に panel 2 を追加 & panel 1 is My Control

この Control For my Project を作成します。この制御コード:

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);
    }
}

Add This control で Form > Create Design Mode For Content のときに行います。パネル1またはタイトルパネルではありません....

このコードは機能しません...すべてのパネルはロックされています。Build Project の後、すべての Changed がリセットされました...

仕事は本当ですか?これを作成する方法は?

 ╔═══════════╗ < Paenl 1
 ║╔═════════╗║
 ║║ Panel 2 ║║
 ║╚═════════╝║
 ║╔═════════╗║
 ║║         ║║
 ║║         ║║
 ║║         ║║
 ║║ Panel 3 ║║ < Design Mode For This Paenl
 ║║         ║║
 ║║         ║║
 ║║         ║║
 ║╚═════════╝║
 ╚═══════════╝

親愛なる@Kingのコードを貼り付けた後、私の問題は解決されません...このエラーは私のプロジェクトにあります:

ここに画像の説明を入力

これは、(@Hans Passant & @King King) 後の他のサンプルのコードです。

    [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");
        }
    }
}
4

1 に答える 1