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.
i tried using flag or boolean but it's nothing working. any other way? other method or properties to achieve this?
thanks.
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.F orm1_Load) ;
private void Form1_Load(object sender, System.EventArgs e)
{
if (Process.GetProcessesByNam e("Windows Applicatio n").Length > 1)
this.Close();
}
Hope this help you.
//using statement
//add this
using System.Diagnostics;
//handle Form-Loadevent of form
this.Load += new System.EventHandler(this.F
private void Form1_Load(object sender, System.EventArgs e)
{
if (Process.GetProcessesByNam
this.Close();
}
Hope this help you.
Check out the singleton pattern:
https://www.experts-exchange.com/questions/20883192/Single-instance-of-a-form-class-URGENT-500-Points.html
https://www.experts-exchange.com/questions/20883192/Single-instance-of-a-form-class-URGENT-500-Points.html
ASKER
(suppose this is winform program named "WindowsApplication")
this WindowsApplication is the project name or the form name ??
hmm ...
this WindowsApplication is the project name or the form name ??
hmm ...
ASKER
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
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks i will try it once i got the time =)
What version? .Net Framework 1.1 (or below) or 2.0?