Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 10th, 2007, 02:03 AM
Registered User
 
Join Date: Nov 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to check form is created or not?

Hi
I am creating a new form at run time when user click on button.
it creates new form each time. now i want to chek out whether form is created or not before creating new one...


 
Old January 11th, 2007, 11:33 AM
Authorized User
 
Join Date: Sep 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

One way would be to add a boolean static member variable to the form. Before creating the form, you could check the state of that variable. When the form is created, and later disposed, you could alter the state of that variable. While I haven't tested the following code, this should give you the idea...

Code:
public class MyOneForm : Form
{
  private static bool s_isCreated = false;
  public static bool IsCreated { return s_isCreated; }

  public MyOneForm()
  {
    s_isCreated = true;
  }

  public void Dispose()
  {
    s_isCreated = false;
  }
}

public class SomeOtherClass
{
  public void DoSomeTask()
  {
    if (MyOneForm.IsCreated)
    {
      // Form has been created already.
    }

    else
    {
      MyOneForm frm = new MyOneForm();
      frm.ShowDialog(this);
      frm.Dispose();
    }
  }
}
Cheers.

- Roger Nedel





Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting onChange Event w/Dynamically Created Form rvanandel Javascript How-To 4 June 28th, 2007 08:10 AM
Retrieving XML created by a form sloanthrasher XML 6 January 16th, 2006 12:25 PM
Check whether a form is already loaded madhukp VB How-To 1 September 8th, 2004 11:34 PM
Check Latin characters in form nikosdra Classic ASP Basics 4 June 27th, 2003 06:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.