gpt4 book ai didi

c# - : Application' is an ambiguous reference between 'System.Windows.Application' and 'System.Windows.Forms.Application' 错误

转载 作者:行者123 更新时间:2023-11-30 15:26:46 30 4
gpt4 key购买 nike

我在 Visual Studio 2013 中运行它。

对于 Application.Current.Shutdown 我得到:

“Application”是“System.Windows.Application”和“System.Windows.Forms.Application”之间的模糊引用

我尝试使用 using SystemInformation = System.Windows.Forms.SystemInformation; 代替 using System.Windows.Forms 一个网站的建议,但我收到错误:

找不到类型或 namespace 名称“OpenFileDialog”(是否缺少 using 指令或程序集引用?) 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);
}
}

最佳答案

试试这个来避免 Application 类的歧义。

private void mnuExit_Click(object sender, RoutedEventArgs e)
{
System.Windows.Application.Current.Shutdown();
}

更新

造成这种歧义的原因是命名空间 System.Windows.FormsSystem.Windows 都包含类 Application 的定义。所以在这一点上,c# 编译器对引用哪个 Application 实现感到困惑。

如果您没有引用 System.Windows.Forms 中的任何类,您可以将其从使用列表中删除。

关于c# - : Application' is an ambiguous reference between 'System.Windows.Application' and 'System.Windows.Forms.Application' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28734752/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com