开发者

Is creating an inheritance chain of WinForms going to bite me?

开发者 https://www.devze.com 2022-12-08 22:10 出处:网络
Suppose I have a base form Main1 which may need to be altered slightly, including perhaps adding additional Controls and altering the开发者_开发技巧 size/location of existing Controls.Those base Contr

Suppose I have a base form Main1 which may need to be altered slightly, including perhaps adding additional Controls and altering the开发者_开发技巧 size/location of existing Controls. Those base Controls which I need to alter I set to 'protected' in the designer. So I have another form, Main2, that derives from Main1. Then I have another form, Main3, which has even more additions/alterations but needs the additions of the 2nd form. And so forth. My inheritance chain looks like: MainX : Main(X - 1) : ... : Main2 : Main1

This works great and allows me to have designer support when moving around and resizing Controls, but I am always wary of inheritance in general and especially when I have a chain this big.

Am I going to pay for this later?


Inheritance is your friend.

Another approach would be to use nested master pages, which may make more sense depending on your application. I'd avoid creating new classes just to change control size or other markup-related content.


I've done this a lot in the past (admittedly not much past 3 or so levels deep) and it's worked pretty well. From time to time the controls seemed to disappear in my "inheriting" form (normally at creation time), but that was back in VS2002/2003 and .net 1.0/1.1. As long as I could call up the finished form successfully (i.e. all controls present and correct) everything was OK.

0

精彩评论

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