开发者

override C# TabControl add method

开发者 https://www.devze.com 2022-12-08 19:43 出处:网络
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 perfo开发者_JS百科rmed.

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 perfo开发者_JS百科rmed.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号