Que*_*Guy 3 c# visual-studio-2013
我在 Visual Studio 2013 中运行它。
因为Application.Current.Shutdown我得到:
'Application' is an ambiguous reference between 'System.Windows.Application' and 'System.Windows.Forms.Application'。
我尝试使用using SystemInformation = System.Windows.Forms.SystemInformation;代替using System.Windows.Forms作为一个网站的建议,但出现错误:
The type or namespace name 'OpenFileDialog' could not be found (are you missing a using directive or an assembly reference?)对于线OpenFileDialog dlg = new OpenFileDialog();
我该如何修复它以便我可以使用 OpenFileDialog?我想要出现一个打开文件对话框。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PTDGUI.View;
private void mnuExit_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.ShowDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
string fileName;
fileName = dlg.FileName;
MessageBox.Show(fileName);
}
}
Run Code Online (Sandbox Code Playgroud)
尝试这样做以避免应用程序类的歧义。
private void mnuExit_Click(object sender, RoutedEventArgs e)
{
System.Windows.Application.Current.Shutdown();
}
Run Code Online (Sandbox Code Playgroud)
更新
造成这种歧义的原因是命名空间System.Windows.Forms和System.Windows包含类的定义Application。所以此时 c# 编译器会混淆要引用哪个应用程序实现。
如果您没有引用任何类,则System.Windows.Forms可以将其从使用列表中删除。
| 归档时间: |
|
| 查看次数: |
13098 次 |
| 最近记录: |