One form, several different programs ?

Poppa Mintin

Well-known member
Joined
Jan 4, 2018
Messages
45
Programming Experience
10+
Hi,
How should I go about writing (say) two different codes for the same one Form ?
I guess I could just make two identical forms and write a code for each, then pick which one to use, but there's bound to be a better way.


Poppa.
 
two different codes for the same one Form
If two forms contain different code then they're not identical. Presumably you mean that the controls on the forms is the same, but the code is just as much a part of the form as the controls are.

In that case, you would create a form as a base class with all the common controls and code, then inherit that form and add the custom code where required. If you need the custom forms in different projects then you would define the base class in a library project and then reference that project or the compiled DLL in the other projects. You would use the Add -> Inherited Form option when adding a new item to your projects instead of Add -> Windows Form when creating the derived classes. Remember that Form is just a class like any other and all the forms you add to your projects are classes that derive from that. The very same inheritance rules apply to those classes as to any other.
 
Oh! ok, that sounds like an interesting new project.
This'll take some time !

Thanks John.

Poppa.
 
Back
Top