Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the state of play with "Visual Inheritance"

We have an application that has to be flexible in how it displays it's main form to the user - depending on the user, the form should be slightly different, maybe an extra button here or there, or some other nuance. In order to stop writing code to explicitly remove or add controls etc, I turned to visual inheritance to solve the problem - in what I thought was a neat, clean and logical OO style - turns out that half the time inherited forms have a hard time rendering themeselves in VS for no good reason etc - and I get the feeling that developers and to some extent Microsoft have shunned the practice of Visual Inheritance - can you confirm this, am I missing something here?

Regards.

like image 608
Vidar Avatar asked Sep 08 '08 10:09

Vidar


2 Answers

I thought they had more or less sorted the desktop designer issues in 2005. Have you tried the usual culprits?

  • No abstract control types
  • No constructor arguments in any form
  • Initialisation moved to Form_Load as opposed to the Ctor
  • No controls in the same project as the usercontrol/form that they are put inside
  • Close all documents -> Clean -> Rebuild
  • Restart VS

I seemed to think that as long as you did all of the above it worked..... mostly.

like image 64
Quibblesome Avatar answered Sep 27 '22 20:09

Quibblesome


I am studying towards the (admittedly soon-to-be-obsoleted) MCAD, and part of the WinForms element was Visual Inheritence.

I personally have had no major problems with it, however, there are considerations to take in to account.

For me, the main problem has always initialization.. You need to remember that the designer cannot/does not instantiate forms in the same way it does at run time (similarly, it cannot do this with web dev, which is why care is needed with custom control rendering).

Also, once a form is changed, a complete re-build of the project is required in order to propagate the changes to the form to the child forms that inherit from it.

I personally have seen no evidence to suggest that it has been "shunned". AFAIK, its still good practice to exercise code re-use where possible. Visual inheritance provides that.

May I suggest creating a new question with the actual problems you are having, with sample code? We can then look at it to see if we can get it working and explain why :)

like image 24
Rob Cooper Avatar answered Sep 27 '22 19:09

Rob Cooper