So, hello, guys. I'm new to this forums and this problem has been bugging me lately. I'm making a Windows Forms app in C#:
So I have a form with two buttons, one of them is a "New" button (private void botonNuevo_Click(object sender, EventArgs e)).
This new button creates a new Form, this is the code of my 'menu':
namespace EGYP
{
public partial class menuBienvenida : Form
{
private void botonNuevo_Click(object sender, EventArgs e)
{
principal principalForm = new principal();
principalForm.Show();
}
}
}
What I want to do, is to make sure is that there can only be one window at a time (the object my "New" button creates). In case it's clicked when there's already an object created, show a Messagebox error, etc.
--
What I wanted to do is to include a counter in my class "menuBienvenida" which is my main form, once the "New" button is clicked and creates the object, increase the counter, and then include a condition in my 'Click' event. Like this:
public partial class menuBienvenida : Form
{
public short counter=0;
private void botonNuevo_Click(object sender, EventArgs e)
{
if(counter==0)
{
principal principalForm = new principal();
principalForm.Show();
counter++;
}
else
MessageBox.Show(...);
}
}
Now the problem is that my other form (the one the "New" button creates) has an exit button, I figured out that I could decrease my counter to 0 again once this button is clicked. But I don't know how to access to my counter from this class.
---
I looked around the code VS generates and Program.cs has something that reads:
static void Main()
{
//other code
Application.Run(new menuBienvenida());
}
I figure out this is the line that creates my main object (my "menu")but I don't know how to refer to this object, since it doesn't have a name...
---
I would really, really, aprecciate your help if you could give me a hand here, I'm starting to code my first WinForms applications because I only knew how to make Console Apps...
Thanks in advance :)