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.StartPosition = FormStartPosition.Manual;
About.Location = new Point(this.Location.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 9 41602
If you are using .NET 2.0, use Application.OpenForms as in:
foreach (Form a in Application.OpenForms)
{
if (a is avernusAbout)
{
// About form is open
break;
}
// About form is not open...
}
<Ke*******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.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.StartPosition = FormStartPosition.Manual;
About.Location = new Point(this.Location.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
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.OpenForms as in:
foreach (Form a in Application.OpenForms)
{
if (a is avernusAbout)
{
// About form is open
break;
}
// About form is not open...
}
<Ke*******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.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.StartPosition = FormStartPosition.Manual;
About.Location = new Point(this.Location.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
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._instance == null)
{
MyForm._instance = new MyForm();
}
return MyForm._instance;
}
}
}
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?
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._instance == null)
{
MyForm._instance = new MyForm();
}
return MyForm._instance;
}
}
}
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?
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.OpenForms)
{
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
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*******@gmail.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._instance == null)
{
MyForm._instance = new MyForm();
}
return MyForm._instance;
}
}
}
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?
Matt's code should do the trick.
<Ke*******@gmail.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.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.OpenForms as in:
foreach (Form a in Application.OpenForms)
{
if (a is avernusAbout)
{
// About form is open
break;
}
// About form is not open...
}
<Ke*******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.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.StartPosition = FormStartPosition.Manual;
About.Location = new Point(this.Location.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
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
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... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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.
|
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?
|
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...
|
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...
|
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...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |