简体   繁体   中英

C# Do something like dynamic inheritance for Windows Forms?

I'm using a third party Windows Forms library that has some Form theming options such as making the form windows look like Office Forms (class Office2007Form) or like Metro Forms (class MetroForm). The library is made by SyncFusion.

https://www.syncfusion.com/products/windows-forms/office2007form

https://www.syncfusion.com/products/windows-forms/metroform

Unfortunately there isn't a single form class where I can set the theme via a property (something like: SyncFusionForm.Theme = Metro). Instead the classes are separate and as such if I want to support both themes, I have to create duplicate forms for each theme with the same controls and nearly identical code.

Is there some way I can dynamically set something like this up perhaps by simulating multiple inheritance with interfaces? I don't have the source for the form classes so my options are not too flexible. To create a SyncFusion themed form, I currently just create a Windows Form and change the base class from 'Form' to either 'Office2007Form' or 'MetroForm' and then there are a few properties I set for color etc...

Please let me know if anyone has some idea of how I can do this without replicating my controls and code. Thanks in Advance!

My first instinct would be to have everything on a UserControl. You then add the user control to either the Office2007Form or MetroForm instance as required.

I follow the Design pattern principle of 'favour composition over inheritence'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM