[英]How can i avoid from showing another Form when closing the program Form1?
In the closing event i have this: 在结束时我有这个:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
FormIsClosing = true;
KeysValuesUpdate();
}
FormIsClosing is a flag. FormIsClosing是一面旗帜。
Then this is the KeysValuesUpdate function: 那么这就是KeysValuesUpdate函数:
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: 问题是,如果即时通信只做(FormIsClosing == true)下一行我不想生效我得到错误:
Error 1 Embedded statement cannot be a declaration or labeled statement And the line after it : dr is unsigned. 错误1嵌入语句不能是声明或带标签的语句和它之后的行:dr是无符号的。
If im doing: 如果即时通讯:
if (FormIsClosing == true)
{
DialogResult dr = crawlLocaly1.ShowDialog(this);
}
Then dr is unsign on this line: if (dr == DialogResult.OK) 然后博士在这一行上没有签名: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);
显示对话框的行是:DialogResult dr = crawlLocaly1.ShowDialog(this);
Your condition refers only to next line as you have put nothing in brackets. 您的条件仅指下一行,因为您没有在括号中放置任何内容。
This should work, I guess: 这应该有用,我想:
using (var w = new StreamWriter(keywords_path_file))
{
if (FormIsClosing == true)
{
crawlLocaly1 = new CrawlLocaly(this);
crawlLocaly1.StartPosition = FormStartPosition.CenterParent;
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);
}
}
}
Update from OP's comment OP的评论更新
Here's how you can display the form when the program is not closing: 以下是程序未关闭时如何显示表单:
DialogResult dr = DialogResult.None;//Increase accessibility domain, setup a good default value
if (FormIsClosing != true)
{
dr = crawlLocaly1.ShowDialog(this);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.