In the closing event i have this:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
FormIsClosing = true;
KeysValuesUpdate();
}
FormIsClosing is a flag.
Then this is the KeysValuesUpdate function:
public void KeysValuesUpdate()
{
using (var w = new StreamWriter(keywords_path_file))
{
if (FormIsClosing == true)
crawlLocaly1 = new CrawlLocaly(this);
crawlLocaly1.StartPosition = FormStartPosition.CenterParent;
if (FormIsClosing == true)
DialogResult dr = crawlLocaly1.ShowDialog(this);
if (dr == DialogResult.OK)
{
if (LocalyKeyWords.ContainsKey(mainUrl))
{
LocalyKeyWords[mainUrl].Clear();
LocalyKeyWords[mainUrl].Add(crawlLocaly1.getText());
}
else
{
LocalyKeyWords[mainUrl] = new List<string>();
LocalyKeyWords[mainUrl].Add(crawlLocaly1.getText());
}
Write(w);
ClearListBox();
}
if (dr == DialogResult.Cancel)
{
Write(w);
}
}
}
The problem is if im doing just if (FormIsClosing == true) the the next line i want not to take effect im getting error on it:
Error 1 Embedded statement cannot be a declaration or labeled statement
And the line after it : dr is unsigned.
If im doing:
if (FormIsClosing == true)
{
DialogResult dr = crawlLocaly1.ShowDialog(this);
}
Then dr is unsign on this line: if (dr == DialogResult.OK)
What i want to archive is that if i close my application just dont show this dialog first.
And the line that show the dialog is: DialogResult dr = crawlLocaly1.ShowDialog(this);
Update from OP’s comment
Here’s how you can display the form when the program is not closing: