LoginSignup
0
0

TableLayoutPanelを持つスーパフォームクラスをサブクラスのデザイナーで編集する方法

Last updated at Posted at 2023-10-14

やりたいこと

TableLayoutPanelを持つフォームクラス(スーパクラス)を継承した、フォームクラス(サブクラス)のデザイナーでTableLayoutPanelを編集したい。

コードは以下のような感じで、SubFormのデザイナー画面でTableLayoutPanelを編集することを想定しています。

public abstract partial class BaseForm
{
	private void InitializeComponent()
	{
		this.tableLyaoutPanel = new System.Windows.Forms.TableLayoutPanel();
		this.tableLyaoutPanel = ColumnCount = 2;
		// 以下省略
	}
	private System.Windows.Forms.TableLayoutPanel tableLyaoutPanel;
}

public abstract partial class BaseForm : Form
{
	public BaseForm()
	{
		InitializeComponent();
	}
}
public partial class SubForm : BaseForm
{
	public SubForm()
	{
		InitializeComponent();
	}
}

結論

まずは結論から。

サブクラスで編集することは出来ません

なぜ出来ないのか?

Microsoftによると、「TableLayoutPanelControlは視覚的継承をデザイナーフォームでサポートしていません。派生クラスではロックされた状態で表示されます。」とのことです。

Avoid Visual Inheritance
The TableLayoutPanel control does not support visual inheritance in the Windows Forms Designer in Visual Studio. A TableLayoutPanel control in a derived class appears as "locked" at design time.

対応策

TableLayoutPanelを使うことはできないので、Panelで代用します。
デフォルトの修飾子はprivateになっているので、protectedまたはpublicにするのを忘れないでください。

参考リンク

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0