在结束时我有这个:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
FormIsClosing = true;
KeysValuesUpdate();
}
FormIsClosing是一面旗帜。
然后这是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);
}
}
}
问题是如果即时通讯只是(FormIsClosing == true)下一行我想要不生效我得到错误:
错误1嵌入式语句不能是声明或带标签的语句 在它之后的行:dr是未签名的。
如果我正在做:
if (FormIsClosing == true)
{
DialogResult dr = crawlLocaly1.ShowDialog(this);
}
然后博士在这一行上没有签名:if(dr == DialogResult.OK)
我要归档的是,如果我关闭我的应用程序,请不要先显示此对话框。 显示对话框的行是:DialogResult dr = crawlLocaly1.ShowDialog(this);
答案 0 :(得分:1)
您的情况仅指下一行,因为您没有在括号中放置任何内容。
这应该有用,我想:
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);
}
}
}
答案 1 :(得分:1)
从OP的评论更新
以下是程序未关闭时如何显示表单:
DialogResult dr = DialogResult.None;//Increase accessibility domain, setup a good default value
if (FormIsClosing != true)
{
dr = crawlLocaly1.ShowDialog(this);
}