Advertisement
BaSs_HaXoR

Form open? and if=true, close. C#

Apr 4th, 2014
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. ///How to check if form is open, and if its already open, close it:
  2. ///CCAPI EXAMPLE:
  3. ///(C#)
  4. using System
  5. using System.IO;
  6.  
  7. if (radioTMAPI.Checked)
  8.             {
  9.                 this.PS3.ChangeAPI(SelectAPI.TargetManager);
  10.             }
  11.             else
  12.             {
  13.                 if (!File.Exists(Directory.GetCurrentDirectory() + "/CCAPI.DLL"))
  14.                 {
  15.                     CCAPIno CCno = new CCAPIno();
  16.                     ipaddress.Enabled = false;
  17.                     this.radioTMAPI.Checked = true;
  18.                     CCno.Show();
  19.                 }
  20.                 else
  21.                 {
  22.                     //   this.rbtnTMAPI.Checked = true;
  23.                 }
  24.             }
  25.  
  26. /////////////////////////////////OTHER FORM -- The Error message saying CCAPI Doesn't exist/////////////////////////////////
  27.  
  28. public CCAPIno()
  29.         {
  30.             InitializeComponent();
  31.             this.FormClosing += this.CCAPIno_Closing;
  32.         }
  33.         static bool s_bFormOpened = false;  // static variable that indicate the form has opened or not
  34.         private void CCAPIno_Load(object sender, EventArgs e)
  35.         {
  36.             {//if one form was opened now, the current form will be closed
  37.                 if (!s_bFormOpened)
  38.                     s_bFormOpened = true;
  39.                 else
  40.                     this.Dispose();
  41.             }
  42.         }
  43.         private void CCAPIno_Closing(object sender, FormClosingEventArgs e)
  44.         {//restored the state
  45.             if (s_bFormOpened)
  46.                 s_bFormOpened = false;
  47.         }
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement