あなたの問題を再現できるかどうかを確認するために、簡単なテスト アプリケーションを作成しました。私が別の方法で行った唯一のことは、デザイナーにパネルを追加し、その可視性を false に設定することでした。それを行うと正しく機能しました。panTitle Panel を手動で作成しているようです。コントロールにいつ/どこに追加するのか、上で述べたようにパネルを追加するのが最善の策です。
編集:
質問をもう少し詳しく読むと、DerivedUserControl の [デザイン] タブを見ているときにパネルを表示したくないようです。私が投稿したことはそれを変更しません。その動作を変更できるかどうかはわかりません。ただし、フォームにドロップしても表示されず、期待どおりに動作します。
これは簡単な作業例です。
フォーム1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
DerivedUserControl dv = new DerivedUserControl();
public Form1()
{
InitializeComponent();
this.Controls.Add(dv);
}
private void button1_Click(object sender, EventArgs e)
{
if (dv.IsTitlePanelVisible)
dv.IsTitlePanelVisible = false;
else
dv.IsTitlePanelVisible = true;
}
}
}
ベース ユーザー コントロール
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class BaseControl : UserControl
{
public BaseControl()
{
InitializeComponent();
}
[DefaultValue(false)]
public bool IsTitlePanelVisible
{
get { return panTitle.Visible; }
set { panTitle.Visible = value; }
}
}
}
BaseControl.Designer.cs InitializeComponent
private void InitializeComponent()
{
this.panTitle = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// panTitle
//
this.panTitle.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(255)))));
this.panTitle.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panTitle.Location = new System.Drawing.Point(0, 0);
this.panTitle.Name = "panTitle";
this.panTitle.Size = new System.Drawing.Size(150, 147);
this.panTitle.TabIndex = 0;
this.panTitle.Visible = false;
//
// BaseControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.panTitle);
this.Name = "BaseControl";
this.ResumeLayout(false);
}
派生ユーザー コントロール
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class DerivedUserControl : BaseControl
{
public DerivedUserControl()
{
InitializeComponent();
}
}
}