Ilya
Ilya

Reputation: 5613

Creating a WinForms custom container control with some non-removable controls

I've written a custom tab control (FooTabControl) which hosts specific tab page controls (FooTabPage instances). The FooTabPages know to place themselves into a dedicated area within the FooTabControl.

Now I wish to have the FooTabControl also host a System.Windows.Forms.Panel child control (in another dedicated area of the FooTabControl). I want the user to be able to place his controls into this Panel, but disallow him from removing the Panel control itself (while still being able to add and remove FooTabPages as he sees fit).

What would be the proper way to implement this?

Upvotes: 1

Views: 1244

Answers (1)

Shay Erlichmen
Shay Erlichmen

Reputation: 31928

You need to override CreateControlsInstance (in the custom control) and return you own implementation of ControlCollection.
In your implementation your will override Remove to disallow removing the Panel.

Upvotes: 4

Related Questions