1

可能重复:
C#、WPF - OpenFileDialog 不出现

我正在尝试制作 John Hunt 的 C# 和面向对象指南中的“JDEdit”应用程序。但是,我像他一样输入了所有代码,每当我尝试使用 ShowDialog() 时,我的应用程序就会冻结。我没有收到任何编译器投诉,所以我不确定发生了什么。

这是我正在尝试实施的方法。检查条件时它会冻结。我认为程序的其余部分不需要发布。

private void Open() {

    // still working

    if (ofd.ShowDialog() == DialogResult.OK) {

        // never makes it here

        string filename = ofd.FileName;
        Console.WriteLine("Open: {0}", filename);
        textArea.TextChanged -= new EventHandler
            (this.TextArea_TextChanged);
        textArea.LoadFile(filename);
        textArea.TextChanged += new EventHandler
            (this.TextArea_TextChanged);
        saveRequired = false;
        this.Text = title + ": " + filename;
    }
}

谢谢!

4

1 回答 1

2

在 Main 上方添加 [STAThread] 可解决此问题。

于 2012-10-07T22:38:22.463 回答