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.
saimatkongAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
Are you using stand alone forms or an MDI interface?

What version?  .Net Framework 1.1 (or below) or 2.0?
0
saimatkongAuthor Commented:
stand alone forms and .Net Framework 1.1
0
quoclanCommented:
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.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Mike TomlinsonMiddle School Assistant TeacherCommented:
0
saimatkongAuthor Commented:
(suppose this is winform program named "WindowsApplication")

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

hmm ...
0
saimatkongAuthor Commented:
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
0
quoclanCommented:
"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.
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Here is how to use TrayForm:

        private void button3_Click(object sender, EventArgs e)
        {
            // get current instance of TrayForm (one will be created if necessary)
            TrayForm tf = TrayForm.Instance();

            // do something with "tf"...
            tf.Show();
        }

Here is TrayForm:

    public partial class TrayForm : Form
    {

        private static TrayForm TrayFormInstance;

        private TrayForm()
        {
            InitializeComponent();            
        }

        public static TrayForm Instance()
        {
            if (TrayFormInstance == null)
            {
                TrayFormInstance = new TrayForm();
                TrayFormInstance.FormClosed += new FormClosedEventHandler(TrayFormInstance_FormClosed);
            }
            return TrayFormInstance;
        }

        static void TrayFormInstance_FormClosed(object sender, FormClosedEventArgs e)
        {
            TrayFormInstance = null;
        }

    }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
saimatkongAuthor Commented:
thanks i will try it once i got the time =)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.