Method 1: Generics, usage: FRM material category Maintenance F = frmcreate<frm material Category Maintenance >.createfrom (this);
Public classFrmcreate<t>whereT:form,New() { Private StaticT instance; Public StaticT createfrom (Form MDI) {if(Instance = =NULL||instance. isdisposed) {instance=NewT (); Instance. StartPosition=Formstartposition.centerscreen; Instance. MdiParent=MDI; Instance. Show (); } instance. WindowState=Formwindowstate.normal; returninstance; } }
Method 2: Reflection, how to use: Form f = frmcreatebyname.createform (This, "basic data. FRM Material category maintenance");
Public classFrmcreatebyname { Public StaticForm CreateForm (Form MDI,stringfrmname) { stringClassName = frmname.substring (Frmname.indexof (".") +1); //guarantee A single case problem foreach(Form frminchapplication.openforms) {if(frm. Name.equals (className))returnfrm; } Assembly Assembly=assembly.getexecutingassembly (); Form instance= assembly. CreateInstance ("Jewelry Processing Management system."+ frmname) asForm; Instance. StartPosition=Formstartposition.centerscreen; Instance. MdiParent=MDI; Instance. WindowState=Formwindowstate.normal; Instance. Show (); returninstance; } }
Form Singleton problem