OpenfileDialog - 窗口未弹出
我正在研究表格。我希望当我单击按钮时弹出小窗口,并从各个文件夹中选择我选择的 XML 文件。
我想,这个 OpenFileDialog 会对我有帮助。
private void button3_Click(object sender, EventArgs e)
{
/
OpenFileDialog OpenFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = " XML Files|*.xml";
openFileDialog1.InitialDirectory = @"D:\";
if (OpenFileDialog1.ShowDialog() == DialogResult.OK)
{
MessageBox.Show(filed.FileName.ToString());
}
}
我尝试使用以下代码,但是当我单击按钮时,不会弹出窗口。 我不明白我犯了什么错误。
这有什么问题吗?
谢谢!
I am working on form . I want small window to pop up when I click button and to will select XML file of my choice from various folder.
I guess, this OpenFileDialog will help me.
private void button3_Click(object sender, EventArgs e)
{
/
OpenFileDialog OpenFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = " XML Files|*.xml";
openFileDialog1.InitialDirectory = @"D:\";
if (OpenFileDialog1.ShowDialog() == DialogResult.OK)
{
MessageBox.Show(filed.FileName.ToString());
}
}
I tried using following code but when I click on the button there window doesn't pop up.
I am not geting what mistake I have made.
What is the problem with that?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能只是打开 来自控制台应用程序的文件对话框。您必须通过一些设置来解决这个问题 single线程公寓 (STA)。
--编辑--
点击事件的以下工作:
You cant just open the file dialog from a console app. You will have to workaround it with some setting to single thread apartment (STA).
--EDIT--
Following works on click event:
您无法在控制台应用程序中打开文件日志。
你说我有按钮,所以这一定是Win应用程序,使用
openFileDialog1.ShowDialog();失踪了
You cant open file fialog in console app.
You say I have button, so this must be Win app, use
openFileDialog1.ShowDialog(); is missing