I would like to create a custom version of the TabControl so that when a new TabPage is added I can ensure some custom processing is performed.
The question is how do I override the TabPages.Add() method to achieve this?
thanks, Richard
I would like to create a custom version of the TabControl so that when a new TabPage is added I can ensure some custom processing is performed.
The question is how do I override the TabPages.Add() method to achieve this?
thanks, Richard
Unfortunatelly, you cannot override Add()
method of TabPageCollection
class. What you may try is to subscribe to TabControl.ControlAdded
event in hope that it will be raised when a TabPage
(which is essentially a Control
as well) will be added.
You could create the custom version which inherits from the TabControl, and has a public new void Add(string)
method. But if anyone casts your control back to the TabControl, they would go around your logic. You could try creating a custom control which inherits from System.Windows.Forms.Control and expose all the methods of a private TabControl, modifying the Add method as needed. This would give you much more control.