473,748 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check if form already Open

Hello, I was wondering if there was a way to check there was already a
form open before opening a new one, sorry that doesnt seem clear, here
is an example:

The following button opens a new form

private void btnAbout_Click( object sender, EventArgs e)
{
avernusAbout About = new avernusAbout();
About.StartPosi tion = FormStartPositi on.Manual;
About.Location = new Point(this.Loca tion.X,
this.Location.Y );
About.Show();
this.Hide();
}

is there a way to check if the form is already open before It opens the
new form?

Any help would be greatly appreciated

Aug 5 '06 #1
9 41661
If you are using .NET 2.0, use Application.Ope nForms as in:

foreach (Form a in Application.Ope nForms)
{
if (a is avernusAbout)
{
// About form is open
break;
}
// About form is not open...
}

<Ke*******@gmai l.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
Hello, I was wondering if there was a way to check there was already a
form open before opening a new one, sorry that doesnt seem clear, here
is an example:

The following button opens a new form

private void btnAbout_Click( object sender, EventArgs e)
{
avernusAbout About = new avernusAbout();
About.StartPosi tion = FormStartPositi on.Manual;
About.Location = new Point(this.Loca tion.X,
this.Location.Y );
About.Show();
this.Hide();
}

is there a way to check if the form is already open before It opens the
new form?

Any help would be greatly appreciated

Aug 5 '06 #2
Maybe I should have provided you with a tad bit more information, what
I needed to do if the form was currently open is show it. How could I
go about doing that?

Siva M wrote:
If you are using .NET 2.0, use Application.Ope nForms as in:

foreach (Form a in Application.Ope nForms)
{
if (a is avernusAbout)
{
// About form is open
break;
}
// About form is not open...
}

<Ke*******@gmai l.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
Hello, I was wondering if there was a way to check there was already a
form open before opening a new one, sorry that doesnt seem clear, here
is an example:

The following button opens a new form

private void btnAbout_Click( object sender, EventArgs e)
{
avernusAbout About = new avernusAbout();
About.StartPosi tion = FormStartPositi on.Manual;
About.Location = new Point(this.Loca tion.X,
this.Location.Y );
About.Show();
this.Hide();
}

is there a way to check if the form is already open before It opens the
new form?

Any help would be greatly appreciated
Aug 5 '06 #3

Ke*******@gmail .com wrote:
Maybe I should have provided you with a tad bit more information, what
I needed to do if the form was currently open is show it. How could I
go about doing that?
Why not make the Form a singleton? Something like this:

public class MyForm : System.Windows. Forms.Form
{
private static MyForm _instance = null;

private void MyForm()
{
... usual constructor stuff ...
}

public MyForm Instance
{
get
{
if (MyForm._instan ce == null)
{
MyForm._instanc e = new MyForm();
}
return MyForm._instanc e;
}
}
}

Now, whenever you want to show the form, just say:

MyForm.Instance .Show();

No need to search, and it works in .NET 1.1 and 2.0. Will that work for
you?

Aug 5 '06 #4
Bruce, I am not sure how to implement that singleton, however I will do
some research on the subject, thankyou all for your help

Bruce Wood wrote:
Ke*******@gmail .com wrote:
Maybe I should have provided you with a tad bit more information, what
I needed to do if the form was currently open is show it. How could I
go about doing that?

Why not make the Form a singleton? Something like this:

public class MyForm : System.Windows. Forms.Form
{
private static MyForm _instance = null;

private void MyForm()
{
... usual constructor stuff ...
}

public MyForm Instance
{
get
{
if (MyForm._instan ce == null)
{
MyForm._instanc e = new MyForm();
}
return MyForm._instanc e;
}
}
}

Now, whenever you want to show the form, just say:

MyForm.Instance .Show();

No need to search, and it works in .NET 1.1 and 2.0. Will that work for
you?
Aug 5 '06 #5

Ke*******@gmail .com wrote:
Maybe I should have provided you with a tad bit more information, what
I needed to do if the form was currently open is show it. How could I
go about doing that?
To use the previous poster's example (which is a good one):

foreach (Form a in Application.Ope nForms)
{
if (a is avernusAbout)
{
a.TopMost = true; // Moves it to the top of the window stack
// or (if it is simply not visible)
a.Visible = true;
}
// About form is not open...

}

Matt

Aug 6 '06 #6
KelsMckin,
Bruce just provided you with a complete working code example of how to do it
as a singleton. All you have to do it try it. There are certainly other ways,
but I'd vote for Bruce's example as being both elegant and simple.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Ke*******@gmai l.com" wrote:
Bruce, I am not sure how to implement that singleton, however I will do
some research on the subject, thankyou all for your help

Bruce Wood wrote:
Ke*******@gmail .com wrote:
Maybe I should have provided you with a tad bit more information, what
I needed to do if the form was currently open is show it. How could I
go about doing that?
Why not make the Form a singleton? Something like this:

public class MyForm : System.Windows. Forms.Form
{
private static MyForm _instance = null;

private void MyForm()
{
... usual constructor stuff ...
}

public MyForm Instance
{
get
{
if (MyForm._instan ce == null)
{
MyForm._instanc e = new MyForm();
}
return MyForm._instanc e;
}
}
}

Now, whenever you want to show the form, just say:

MyForm.Instance .Show();

No need to search, and it works in .NET 1.1 and 2.0. Will that work for
you?

Aug 6 '06 #7
Matt's code should do the trick.

<Ke*******@gmai l.comwrote in message
news:11******** **************@ p79g2000cwp.goo glegroups.com.. .
Maybe I should have provided you with a tad bit more information, what
I needed to do if the form was currently open is show it. How could I
go about doing that?

Siva M wrote:
If you are using .NET 2.0, use Application.Ope nForms as in:

foreach (Form a in Application.Ope nForms)
{
if (a is avernusAbout)
{
// About form is open
break;
}
// About form is not open...
}

<Ke*******@gmai l.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
Hello, I was wondering if there was a way to check there was already a
form open before opening a new one, sorry that doesnt seem clear, here
is an example:

The following button opens a new form

private void btnAbout_Click( object sender, EventArgs e)
{
avernusAbout About = new avernusAbout();
About.StartPosi tion = FormStartPositi on.Manual;
About.Location = new Point(this.Loca tion.X,
this.Location.Y );
About.Show();
this.Hide();
}

is there a way to check if the form is already open before It opens the
new form?

Any help would be greatly appreciated
Aug 6 '06 #8
a.TopMost = true; // Moves it to the top of the window stack

IIRC, this toggles the "always on top" behaviour; a combination of
Activate(), Focus() and BringToFront() would probably be more in order,
otherwise the user could find it hard to get rid of the form (to the
background) afterwards.

Marc
Aug 8 '06 #9
Bruce Wood wrote:

[...]
Why not make the Form a singleton? Something like this:
[...]

This will work if there'll only ever be one instance of that form. But
sometimes, you'll have to make sure there's only one instnce of a certain
form per business object, e. g. to open a customer form once per customer
and bring it to top otherwise.

We're keeping a Dictionary of our opened forms with a combination of form
class name and business object id as a key and look it up whenever we want
to open a new view, then proceed pretty much as you did...
Aug 8 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6488
by: ST | last post by:
This is my other error when I click on Immunoflourescence. I believe this is related to the other error I just posted (Input string was not in a correct format.) Please let me know if you have any suggestions! Thanks! The connection is already Open (state=Open). Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where...
3
3958
by: P | last post by:
Hi, Access 2002. I use DoCmd.OpenForm attached to command buttons to open one form from another form. All forms are open in dialog mode. When a user tries to open a form already opened from a form in dialog mode, nothing happens as expected. I would like to inform the users that the form does not open because it is already opened in the background. What event do you suggest using for this? Thank you. P
2
1598
by: nTn | last post by:
Hi! I open a new form in my Mdi. But if I click in button again to open this form, the program create another form. How I can check if the form is already open? I'm using that: Dim frmUsuarios As New usuarios("Usuarios", Me)frmUsuarios.Show()
3
10587
by: Shelby | last post by:
Hi, how can I check that if the form is already open? Whenever I click on a button, it will open the form. I would like to check if the form is open.
2
1838
by: John | last post by:
Hi I am opening a dialog using; frmdialog = New frmdialognew frmdialog.ShowDialog() Is there a way to see if this dialog is already open to avoid opening multiple instances of it?
1
9922
by: stevencarroll19 | last post by:
What i wnat to do is check to see if a form is open before a new record can be entered. If any of the forms are open ( Question3 Reason, Question 4 Reason and Question 9 Comments) I want an error message to be displayed saying something along the lines of 'Sorry you have 'form name here' open. Please click save on the form before continuing' I started to write a macro which included the run code command but got stuck on the vb and also...
1
2829
by: keri | last post by:
Hi, I use the below for the user to view their outlook calendar Sub DisplayInbox() Dim myolApp As Outlook.Application Dim myNameSpace As Outlook.NameSpace Dim myFolder As Outlook.MAPIFolder Set myolApp = CreateObject("Outlook.Application") Set myNameSpace = myolApp.GetNamespace("MAPI")
19
19042
by: =?Utf-8?B?R3JlZw==?= | last post by:
How can I tell via code if a Form is already open. Each time my forms load I have some initialization code that runs, but if the form is already open and hidden I don't want that initialization code to run. Thus, I just want to unhide the form. My thought is eveyrtime I go to load a form I could scan through all the open forms in my project and determine whether the one I'm getting ready to load is open or not.
2
3073
by: KA NMC | last post by:
Current application is built in VB.net 2005 what it does is open other small applications within the form. I'm not using mdi I probably should. Here is my problem The application load - main form only contains a menu strip - once selecting a menu option another form opens within the main form. What I want the app to do is; to check to make sure that the sub form is not already open. If it is bring it to front. My code.. I created a...
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8243
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.