0

在闭幕式中,我有这个:

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);
                }
            }
        }

问题是如果我只是在做 if (FormIsClosing == true) 下一行我不想生效我得到错误:

错误 1 ​​嵌入式语句不能是声明或带标签的语句,并且它后面的行 : dr 是无符号的。

如果我在做:

if (FormIsClosing == true)
{
                    DialogResult dr = crawlLocaly1.ShowDialog(this);
}

然后 dr 在这一行上取消签名: if (dr == DialogResult.OK)

我要存档的是,如果我关闭我的应用程序,则不要先显示此对话框。显示对话框的行是:DialogResult dr = crawlLocaly1.ShowDialog(this);

4

2 回答 2

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);
            }
            }
        }
于 2013-02-19T14:06:19.913 回答
1

OP评论的更新

以下是程序未关闭时显示表单的方法:

            DialogResult dr = DialogResult.None;//Increase accessibility domain, setup a good default value
            if (FormIsClosing != true)
            {
              dr = crawlLocaly1.ShowDialog(this);
            }
于 2013-02-19T14:07:27.827 回答