dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.29k stars 956 forks source link

Derived form of a base form fails to accept and display new controls in it #11429

Closed nangelgr closed 1 month ago

nangelgr commented 1 month ago

.NET version

8.0.200

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

No response

Issue description

I created a simple form that will be used as a base dialog for the rest of the dialogs. The base dialog contains a docked tablelayoutpanel control with two rows and one column. The first row of this tableloutpanel contains a new tablelayoutpanel control with one col and one row and a label in the latter So far so good This compiles normally and the derived dialog displays normally The problems begin when i try to add a new tablelayoutpanel in the second row of the tablelayoutpanel coming from the base dialog. The new control can not be added and also not showing up not even into the Document outline pane.

Steps to reproduce

Create a form that will be used as base dialog form named D1 in D1 create a tablelayoutpanel TLP1 with 1 col and 2 rows. In the first cell of the TLP1 create a new label L1 Now create a second form named derivedD2 : D1 instead of derivedD2 : Form The contents of the D1 showing up correctly in the D2 dialog Now try to add a new tablelayoutpanel in the second cell (cell of col 0 and row 1) Mine? Fails!! No new control can be added to the empty cell and also no new control shows up in the document outline pane Bug? or my mistake?

elachlan commented 1 month ago

@Olina-Zhang can your team please test this?

Olina-Zhang commented 1 month ago

Tested it in .NET and .NET framework, they have same behavior. It is "By design". Referring to "Note" area in the Doc: By default, the Windows Forms Designer assigns the private (Friend in Visual Basic) modifier to container controls like Panel. If your base UserControl or Form has a container control, it will not accept new children in inherited controls and forms. The solution is to change the modifier of the base container control to protected or public.