I've written a custom tab control (FooTabControl
) which hosts specific tab page controls (FooTabPage
instances). The FooTabPage
s know to place themselves into a dedicated area within the FooTabControl
.
我编写了一个自定义选项卡控件(FooTabControl),它托管特定的选项卡页面控件(FooTabPage实例)。 FooTabPages知道将自己置于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 FooTabPage
s as he sees fit).
现在我希望FooTabControl还托管一个System.Windows.Forms.Panel子控件(在FooTabControl的另一个专用区域中)。我希望用户能够将他的控件放入这个Panel,但是不允许他移除Panel控件本身(同时仍然能够按照他认为合适的方式添加和删除FooTabPages)。
What would be the proper way to implement this?
实现这个的正确方法是什么?
1 个解决方案
#1
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.
您需要覆盖CreateControlsInstance(在自定义控件中)并返回您自己的ControlCollection实现。在您的实现中,您将覆盖删除以禁止删除Panel。
#1
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.
您需要覆盖CreateControlsInstance(在自定义控件中)并返回您自己的ControlCollection实现。在您的实现中,您将覆盖删除以禁止删除Panel。