The code:
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
crawlLocaly1 = new CrawlLocaly();
crawlLocaly1.StartPosition = FormStartPosition.CenterParent;
OptionsDB.Set_localOnly(checkBox2.Checked);
if (checkBox2.Checked)
{
DialogResult dr = crawlLocaly1.ShowDialog(this);
if (dr == DialogResult.Cancel)
{
crawlLocaly1.Close();
}
else if (dr == DialogResult.OK)
{
LocalyKeyWords.Add(crawlLocaly1.getText());
crawlLocaly1.Close();
}
removeExt = true;
}
else
{
removeExt = false;
}
}
This line:
OptionsDB.Set_localOnly(checkBox2.Checked);
Save the state of the checkBox2 if its checked or not. If its checked next time i will run my program i will see the V in the checkBox2 checked box. If i will uncheck the checkBox next time i run my program the box of the checkBox2 will be unchecked.
The problem is when i check the checkBox2 once close my program and run it again since the checkBox is checked now then for some reason it will make this:
DialogResult dr = crawlLocaly1.ShowDialog(this);
Wich will open and show the user a new Form.
But i dont want it to be like that.
I want that if the user checked the checkBox when the program is running the new Form will show up. But if the user is running the program from the beginning and the checkBox is checked dont show the new Form just show that the checkBox is checked !
How should i fix it ?
You need an other boolean flag
checkedInThisSessionwhich initially set tofalse, and just set it to true in a checkboxOnCheckedhandler, then you can check this state easily. Hope all is clear