Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
747 views
in Technique[技术] by (71.8m points)

c# - Visual Inheritance - Add controls at designer to a Panel hosted in TableLayoutPanel

I'm making a base form (WinForm) to use like a blueprint for my general form design, I want the panel (P_Content in the screenshot) to be where controls are put in the Child Forms.

But said P_Content is locked in the child forms, adding controls in the code obviously works but it does not in Design View.

The panel is public and so is its parent containers (TableLayoutPanel).

This seems really basic but I can't seem to find any answer why this is happening.

P_Content being the big empty space.

Screenshot

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Its seems you have hosted the Panel in a TableLayoutPanel. According to the documentations you should avoid visual inheritance for TableLayoutPanel:

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

The behavior is not limited to TableLayoutPanel and it's documented that some other controls also do not support visual inheritance from the base form and will be always read-only and appear as locked in the inherited form regardless of the modifiers you use:

Not all controls support visual inheritance from a base form. The following controls do not support the scenario described in this walkthrough:

  • WebBrowser
  • ToolStrip
  • ToolStripPanel
  • TableLayoutPanel
  • FlowLayoutPanel
  • DataGridView

These controls in the inherited form are always read-only regardless of the modifiers you use (private, protected, or public).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...