<p>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?</p>

<p>Regards.</p>

[{'answer_id': 49474, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 1, 'selected': False, 'text': '<p>I often stumble upon such problems in Visual Studio. In many cases MSVS forms designer fails to render form correctly. Back in the days I worked with WinForms I had to do all kind of weird tricks to enable some complex scenarios. However I think that using visual inheritance is very beneficial and should not be thrown away regardless of MSVS designer bugs.</p>\n'}, {'answer_id': 49513, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 2, 'selected': False, 'text': '<p>I am studying towards the (admittedly soon-to-be-obsoleted) MCAD, and part of the WinForms element was Visual Inheritence.</p>\n\n<p>I personally have had no major problems with it, however, there <strong>are considerations to take in to account</strong>.</p>\n\n<p>For me, <strong>the main problem has always initialization</strong>.. 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).</p>\n\n<p>Also, <strong>once a form is changed, a complete re-build of the project is required</strong> in order to propagate the changes to the form to the child forms that inherit from it.</p>\n\n<p>I personally have seen no evidence to suggest that it has been "shunned". <strong>AFAIK, its still good practice to exercise code re-use where possible. Visual inheritance provides that.</strong></p>\n\n<p>May I suggest creating a new question with the <em>actual</em> problems you are having, with sample code? We can then look at it to see if we can get it working and explain why :)</p>\n'}, {'answer_id': 49526, 'author': 'Quibblesome', 'author_id': 1143, 'author_profile': 'https://Stackoverflow.com/users/1143', 'pm_score': 4, 'selected': True, 'text': '<p>I thought they had more or less sorted the desktop designer issues in 2005.\nHave you tried the usual culprits?</p>\n\n<ul>\n<li>No abstract control types</li>\n<li>No constructor arguments in any form</li>\n<li>Initialisation moved to Form_Load as opposed to the Ctor</li>\n<li>No controls in the same project as the usercontrol/form that they are put inside</li>\n<li>Close all documents -> Clean -> Rebuild</li>\n<li>Restart VS</li>\n</ul>\n\n<p>I seemed to think that as long as you did all of the above it worked..... mostly.</p>\n'}, {'answer_id': 49554, 'author': 'Mendelt', 'author_id': 3320, 'author_profile': 'https://Stackoverflow.com/users/3320', 'pm_score': 2, 'selected': False, 'text': "<p>I've seen some problems in VS2005 with this. They were mostly due to problems with construction of the forms-objects in the designer. There were issues with code that tried to access the database from the form-constructors etc.</p>\n\n<p>You can debug issues like this by starting a second instance of visual studio and loading up the first instance in the debugger. If you set breakpoints in your code you can then debug what happens in the designers in the first instance.</p>\n\n<p>Another problem I can remember was generics in form classes</p>\n\n<pre><code>public class MyForm&lt;MyObject&gt; : Form\n</code></pre>\n\n<p>this won't work</p>\n"}, {'answer_id': 258868, 'author': 'Tigraine', 'author_id': 21699, 'author_profile': 'https://Stackoverflow.com/users/21699', 'pm_score': 1, 'selected': False, 'text': "<p>I think I've found a way how to avoid this problem.</p>\n\n<p>Don't hook the Form_Load Event in your parent form, this will break the designer.</p>\n\n<p>Also don't take the Default empty constructor away from Visual Studio in the Parent Form. If you want to have Dependency Injection, create another constructor.</p>\n\n<p>Like this:</p>\n\n<pre><code>public ProductDetail()\n{\n    InitializeComponent();\n}\n\npublic ProductDetail(ISupplierController supplierController) : base()\n{\n    InitializeComponent();\n    this.supplierController = supplierController;\n}\n</code></pre>\n\n<p>You can then still do this from your inherited Form:</p>\n\n<pre><code>public NewProduct(ISupplierController supplierController)\n    : base(supplierController)\n{\n    InitializeComponent();\n}\n</code></pre>\n\n<p>This worked for me so far, and I had some weird designer issues too.</p>\n\n<p>cheers, Daniel</p>\n"}, {'answer_id': 2161821, 'author': 'Trygve Lorentzen', 'author_id': 261795, 'author_profile': 'https://Stackoverflow.com/users/261795', 'pm_score': 0, 'selected': False, 'text': '<p>Read this: <a href="http://cs.rthand.com/blogs/blog_with_righthand/archive/2005/11/10/186.aspx" rel="nofollow noreferrer">http://cs.rthand.com/blogs/blog_with_righthand/archive/2005/11/10/186.aspx</a></p>\n\n<p>AFAIK, there are still issues with Visual Inheritance and objects that rely on collections for the design elements, typically grid controls etc. I believe MS still have removed the possibility of changing f.ex. a GridView in an inherited form/usercontrol etc. But other controls like TextBox, Form, UserControl, Panel etc. should work as expected.</p>\n\n<p>I\'ve so far had no problem with VI using 3rd party grid controls myself, but you have to be careful, in particular, removing items from collections MUST be avoided.</p>\n'}]
['https://Stackoverflow.com/questions/49458', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5175/']