Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Window's form

Posted on 2006-04-12
9
Medium Priority
?
285 Views
Last Modified: 2010-04-16
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.
0
Comment
Question by:saimatkong
  • 4
  • 3
  • 2
9 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16440010
Are you using stand alone forms or an MDI interface?

What version?  .Net Framework 1.1 (or below) or 2.0?
0
 

Author Comment

by:saimatkong
ID: 16441918
stand alone forms and .Net Framework 1.1
0
 
LVL 2

Expert Comment

by:quoclan
ID: 16450941
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16450966
0
 

Author Comment

by:saimatkong
ID: 16451551
(suppose this is winform program named "WindowsApplication")

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

hmm ...
0
 

Author Comment

by:saimatkong
ID: 16451612
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
 
LVL 2

Expert Comment

by:quoclan
ID: 16451784
"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
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 150 total points
ID: 16453671
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
 

Author Comment

by:saimatkong
ID: 16483826
thanks i will try it once i got the time =)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question