Reputation: 327
I'm trying to set up a basic system of having a 'master' or 'template' windows form (in Visual Studio Express c#) which has a few basic buttons and properties, and then adding new forms which inherit from that and extend its functionality. My exact implementation doesn't matter here, as I'll be wanting to use this kind of thing for loads of projects.
MSDN and every source I can find tells me to add a new Inherited Form from the solution explorer, however the Inherited Form template does not appear in the menu, and my friend who was the full Visual Studio 2010 can't find it either. I tried every command line command I could find online to install templates: devenv /installvstemplates, vcsexpress /setup vcsexpress /installvstemplates etc.. but they appear to have no effect whatsoever, giving no error or acknowledgement, but the template is still missing.
Think I've solved the issue by following below suggestions and by making sure to call base() from the constructor, and explicitly calling InitializeComponent() from the constructor of the inherited form - seems strange that said function isn't virtual, but I'm sure there's a reason.
How can I get this template? Can someone export it to me? Is it not supported or something?
If Inherited Form is not the way to go, how can I create forms inheriting from each other and be able to edit them in the designer without every change being undone upon build?
Upvotes: 0
Views: 2430
Reputation: 28079
All you need to do is design the form you wish to inherit from, and then when you create a new blank form, change the inheritance in the code-behind from Form to whatever your forms name is.
So, double click on your form to get to the code behind, look for something resembling this at the top:
public partial class MyForm : Form
And change it to this:
public partial class Myform : BaseForm
Just to demonstrate that this works, a screenshot is below:
Upvotes: 4
Reputation: 2603
Simply first create a normal form and name it e.g. BaseForm. Design it as you would like and add all the standard features.
Then when you want to create a new one, simply derive it from BaseForm instead of Form.
public partial class BaseForm : Form {
// example property
protected string Test { get; set; }
}
public partial class MyInheritedForm : BaseForm {
// now the inherited form has also access to previously declared protected prop
}
The template you're talking about is actually not doing more than this specific inheritance via a wizard dialog
Upvotes: 3