Reputation: 333
I'm running this in Visual Studio 2013.
For Application.Current.Shutdown
I get:
'Application' is an ambiguous reference between 'System.Windows.Application' and 'System.Windows.Forms.Application'
.
I tried using using SystemInformation = System.Windows.Forms.SystemInformation;
in place of using System.Windows.Forms
as one site suggested but I get the error:
The type or namespace name 'OpenFileDialog' could not be found (are you missing a using directive or an assembly reference?)
for the line OpenFileDialog dlg = new OpenFileDialog();
How can I fix it so I can use OpenFileDialog? I want an open file dialog box to appear.
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);
}
}
Upvotes: 4
Views: 15704
Reputation: 6766
Try this to avoid ambiguity of Application class.
private void mnuExit_Click(object sender, RoutedEventArgs e)
{
System.Windows.Application.Current.Shutdown();
}
Update
The reason for this ambiguity is both namespace System.Windows.Forms
and System.Windows
contains definition for class Application
. so at this point c# compiler gets confused which implementation of Application to refer to.
If you are not referring any classes from System.Windows.Forms
you can remove it from the list of using.
Upvotes: 5