c# - Multiple exactly the same forms -


i have multiple forms same (invoice, priceoffer, order,...) created first form. after thinking this, other forms same.

is there technique, or other way prevents me of creating forms on , on again?

just create single form class you'd call orderform or that

public class orderform : form {  } 

then use create controls on it, , create instance of class every time need show user. best part of if 1 of forms changes (let's invoice) inherit class , change part different:

public class invoiceform : orderform {  } 

and create instance of invoiceform when need that.

edit answering ops question in comment.

let's create bunch of controls in constructor of orderform :

public class orderform : form {     public orderform {          var button = new button() { ... };          var label = new label () { ... };          this.controls.add(button);          this.controls.add(label);     } } 

now if you'd create instance of orderform, these controls added form, no matter how many instances you'd create of these:

//each of these instances have same controls var form1 = new orderform(); var form2 = new orderform(); var form3 = new orderform(); 

now if you'd define subclass of orderform namely invoiceform, you'd able use same form controls orderform, changes it:

public class invoiceform : orderform {     public invoiceform() : base(){ // : base() executes constructor of superclass         //all controls in `orderform` class added because called base().         var invoicecontrol = new label() { ... };         this.controls.add(invoicecontrol);          //now in total form count 4 controls     } } 

now can create instance of invoicecontrol changed form.

//first 2 forms have 3 controls, last 2 forms have 4 controls. var form1 = new orderform(); var form2 = new orderform(); var form3 = new invoiceform(); var form4 = new invoiceform(); 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -