i have a Form which has a button, on the button click event, a variable locklogin is increased by 1
when locklogin =3 , then the form button gets disabled and the form needs to be closed. on closing the form , locklogin loses its value.
but i want to hold its value albeit the form being closed and when the form is run again(the whole application is executed again), then the button is still disabled. how do i do this?
public partial class Form1 : Form
{
static int loginlocked;
static int isloginlocked;
public Form1()
{
InitializeComponent();
if (isloginlocked == 3)
{
foreach (Control c in this.Controls)
{ c.Enabled = false; }
}
}
private void button1_Click(object sender, EventArgs e)
{
loginlocked++;
if (loginlocked == 3)
{
foreach (Control c in this.Controls)
{ c.Enabled = false; }
this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
isloginlocked = loginlocked;
if (e.CloseReason == CloseReason.UserClosing)
{
if (MessageBox.Show(this, "Really?", "Closing...",
MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
== DialogResult.Cancel) e.Cancel = true;
}
}
}
i want that when the form/application is opened then first it checks whether the value of the variable is =3 , and if its 3 ,then it should disable the button on it.