Home > Net >  C # form switch
C # form switch

Time:09-20

C # in the form of a string to determine whether a form is opened, if you open display, if there is no open open

CodePudding user response:

If (Application. OpenForms [" ST_WorkStation "]==null)
{
ST_WorkStation obj_FM=new ST_WorkStation ();
Obj_FM. MdiParent=this;
Obj_FM. The Show ();
}
The else
{
Application. OpenForms [" ST_WorkStation "]. Activate ();
}

CodePudding user response:

ST_WorkStation is form the name of the class

CodePudding user response:

All open form, in a dictionary,
According to the existence of the key and judgment

CodePudding user response:

 Form test=Application. OpenForms [" relock "];//find ever open the lock window 
If ((test==null) | | (test. IsDisposed))//if there is no open
{

//... Open the code
}
The else
{
Test. The Activate ();//if the focus has been open and let them get
Test. The WindowState=FormWindowState. Normal;//Form the Form returned to normal size
}

CodePudding user response:

Do a static dictionary, the key to form the type of the name, the value for the form, use a dictionary every time

CodePudding user response:

All open form, in a dictionary,
According to the existence of the key and judgment

CodePudding user response:

//has been testing, can run normally

FormCollection collection=Application. OpenForms;//get all the open form
Bool isOpen=false;//determine whether open
Foreach (Form the Form in the collection)
{
If (form. The Text=="Form2")//open the forms of the form, if the activation
{
Form. The Activate ();
IsOpen=true;
break;
}
}
if(! IsOpen)//does not open the window, open it
{
Form2 frm2=new Form2 ();
Frm2. The Show ();
}
  •  Tags:  
  • C #
  • Related