Link to home
Start Free TrialLog in
Avatar of saimatkong
saimatkong

asked on

Window's form

how to check is this form is activatted then don't open this form again until it's not activated or close.
i tried using flag or boolean but it's nothing working. any other way? other method or properties to achieve this?
thanks.
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Are you using stand alone forms or an MDI interface?

What version?  .Net Framework 1.1 (or below) or 2.0?
Avatar of saimatkong
saimatkong

ASKER

stand alone forms and .Net Framework 1.1
Use this code (suppose this is winform program named "WindowsApplication")
//using statement
//add this
using System.Diagnostics;

//handle Form-Loadevent of form
this.Load += new System.EventHandler(this.Form1_Load);


private void Form1_Load(object sender, System.EventArgs e)
            {
                  if (Process.GetProcessesByName("WindowsApplication").Length > 1)
                        this.Close();
            }

Hope this help you.
(suppose this is winform program named "WindowsApplication")

this WindowsApplication is the project name or the form name ??

hmm ...
Idle_Mind i dun really understand that.

ok wat i did was. is this correct ?
i wanna access the fucntion to set config.active = true in trayform without creating another instance.

public TrayForm{
    private Configuration config;

     private void TrayForm_Load(object sender, System.EventArgs e)
    {
     config = new Configuration();
    }

     public static TrayForm Instance()
    {
          config.active = true;
     }
}





So instead of:

TrayFormmy tray = new TrayForm();

you would use:

TrayForm tray = TrayForm.Instance();


thanks
"WindowsApplication" is a project name.
My method is suitable for 1 application (1 or many forms) only exist 1 instance.
I think Idle_Mind's method is suitable for you.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks i will try it once i got the time =)