本文整理汇总了C#中Microsoft.Win32.OpenFileDialog.ShowDialog方法的典型用法代码示例。如果您正苦于以下问题:C# OpenFileDialog.ShowDialog方法的具体用法?C# OpenFileDialog.ShowDialog怎么用?C# OpenFileDialog.ShowDialog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Win32.OpenFileDialog
的用法示例。
在下文中一共展示了OpenFileDialog.ShowDialog方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnAdd_Click
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
bool? result = null;
OpenFileDialog fileDlg = new OpenFileDialog();
fileDlg.Filter = "Dynamic Linked Libraries|*.dll";
fileDlg.Title = "Add Plugin Assembly...";
fileDlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
result = fileDlg.ShowDialog(this);
if (result != null && result == true)
{
if (ValidateAndAddAssembly(fileDlg.FileName))
{
// Notify the user of the impending restart
MessageBox.Show(this, "The application must now restart to ensure the Plugin is fully functional.", "Plugin Added!", MessageBoxButton.OK, MessageBoxImage.Information);
// Restart
try
{
Process.Start(Application.ResourceAssembly.Location);
Application.Current.Shutdown();
}
catch (Exception ex)
{
PluginManager.log.Error("An exception was thrown while attempting to restart the application as a result of a plugin removal.", ex);
}
}
}
}
示例2: BtnImportClick
private void BtnImportClick(object sender, RoutedEventArgs e)
{
var ofd = new OpenFileDialog
{
Filter = "Text files (*.txt)|*.txt"
};
var result = ofd.ShowDialog();
if (result == true)
{
if (!File.Exists(ofd.FileName))
{
return;
}
var accounts = Utils.GetLogins(ofd.FileName);
var num = 0;
foreach (var account in accounts)
{
if (!Checker.Accounts.Exists(a => a.Username == account.Username))
{
Checker.Accounts.Add(account);
num++;
}
}
this.ShowMessageAsync(
"Import", num > 0 ? string.Format("Imported {0} accounts.", num) : "No new accounts found.");
RefreshAccounts();
MainWindow.Instance.UpdateControls();
}
}
示例3: OnLoadModule
private void OnLoadModule(object sender, System.Windows.RoutedEventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog()
{
CheckFileExists = true,
Filter = "Binary Files (*.bin, *.exe, *.img, *.iso, *.o)|*.bin;*.exe;*.img;*.iso;*.o|"
+ "All Files (*.*)|*.*|Image Files (*.img, *.iso)|*.img;*.iso|"
+ "Object Files (*.bin, *.o, *.exe)|*.bin;*.o;*.exe",
FilterIndex = 0,
Title = "Select Debug Binary",
Multiselect = true,
};
bool? result = dialog.ShowDialog(this);
if (result.HasValue && result.Value)
{
foreach (string modulePath in dialog.FileNames)
{
try
{
Loader.LoadImage(modulePath, null);
}
catch (Exception x)
{
var msg = String.Format("An error occured and the module '{0}' "
+ "has not been loaded:\n{1}", modulePath, x.ToString());
MessageBox.Show(msg, "Error Loading Module", MessageBoxButton.OK,
MessageBoxImage.Error);
}
}
this.RefreshItems();
}
}
示例4: Button_Click_1
private void Button_Click_1(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
const string initialDirectory = "g:\\temp\\";
if (Directory.Exists(initialDirectory))
openFileDialog1.InitialDirectory = initialDirectory;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == true)
{
var result = LogParser.Parse(openFileDialog1.FileName);
_battles = LogParser.DivideIntoBattlesAndApplyGuards(result);
ListBattles.Items.Clear();
ListBattles.BeginInit();
foreach (var battle in _battles)
{
ListBattles.Items.Add(battle.ToString());
}
ListBattles.EndInit();
}
}
示例5: NewOutputFormatMenuItem_Click
private void NewOutputFormatMenuItem_Click(object sender, RoutedEventArgs e)
{
ClearCanvas();
var newOutputFormatOpenFileDialog = new OpenFileDialog
{
Filter = "dll files (*.dll)|*.dll",
DefaultExt = ".dll",
Title = "Please select dll file"
};
if (newOutputFormatOpenFileDialog.ShowDialog() == true)
{
string pathToCopy = Path.Combine(AssemblyPath, @"Printers\",
Path.GetFileName(newOutputFormatOpenFileDialog.FileName));
try
{
File.Copy(newOutputFormatOpenFileDialog.FileName, pathToCopy, true);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
MessageBox.Show("Printer added successfully!", "Information", MessageBoxButton.OK,
MessageBoxImage.Information);
}
}
示例6: _vmSaveFileInteractionEvent
private void _vmSaveFileInteractionEvent(object sender, InteractionRequestedEventArgs e)
{
SaveFileConfirmation _confirmation = e.Context as SaveFileConfirmation;
if (_confirmation == null)
return;
string _msg = $"Click Yes to save configuration to {_confirmation.FilePath}, No to slecet new file, Cancel to cancel";
//switch (MessageBox.Show(_confirmation.Title, _msg, MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Cancel))
switch (MessageBox.Show(_msg, _confirmation.Title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Cancel))
{
case MessageBoxResult.None:
case MessageBoxResult.OK:
case MessageBoxResult.Yes:
break;
case MessageBoxResult.Cancel:
_confirmation.FilePath = string.Empty;
break;
case MessageBoxResult.No:
OpenFileDialog _dialog = new OpenFileDialog()
{
AddExtension = true,
CheckPathExists = true,
DefaultExt = ".xml",
Filter = "Configuration (.xml)|*.xml",
FileName = _confirmation.FilePath,
Title = "Save file as ..",
CheckFileExists = false,
ValidateNames = true,
};
_confirmation.FilePath = _dialog.ShowDialog().GetValueOrDefault(false) ? _dialog.FileName : string.Empty;
e.Callback();
break;
default:
break;
}
}
示例7: OpenTest
public static string OpenTest(string courseName_copy, string groupName_copy, string testName_copy)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "TST Files (*.tst) |*.tst";
Nullable<bool> resultOfDialog = openFileDialog.ShowDialog();
string resultOfParsing;
_courseName = courseName_copy;
_groupName = groupName_copy;
_testName = testName_copy;
if (resultOfDialog == true)
{
string pathOfTest = openFileDialog.FileName;
SelectDirectoryPath(pathOfTest);
try
{
resultOfParsing = TestParser.Instance.ParseTest(pathOfTest, folderPath);
}
catch(Exception)
{
resultOfParsing = "Wystąpił problem podczas odczytu plik";
}
if(resultOfParsing == "Ok")
{
ZipDirectory(folderPath, fileName);
if(IS_OK == true)
unzipTest();
}
return resultOfParsing;
}
return "";
}
示例8: Execute
/// <summary>
/// vykonávacia logika príkazu
/// </summary>
/// <param name="parameter">parameter príkazu</param>
public void Execute(object parameter)
{
if (((MainWindowViewModel)parameter).HadProject == true)
{
string messageText = "Nemôžu byť otvorené dva projekty súčasne. Vymazať projekt?";
string messageCaption = "Vymazať projekt";
MessageBoxResult res = MessageBox.Show(messageText, messageCaption, MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Cancel);
if (res == MessageBoxResult.Yes)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "XML documents (.xml)|*.xml";
if (dialog.ShowDialog() == true)
{
string filename = dialog.FileName;
((MainWindowViewModel)parameter).Load(filename);
}
}
((MainWindow)Application.Current.MainWindow).mainFrame.Navigate(new Uri("Views/Pages/WelcomePage.xaml", UriKind.Relative));
}
else
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "XML documents (.xml)|*.xml";
if (dialog.ShowDialog() == true)
{
string filename = dialog.FileName;
((MainWindowViewModel)parameter).Load(filename);
}
((MainWindowViewModel)parameter).HadProject = true;
}
}
示例9: ExecuteOpenFileDialog
public void ExecuteOpenFileDialog()
{
var dialog = new OpenFileDialog { InitialDirectory = _defaultPath };
dialog.ShowDialog();
SelectedPath = dialog.FileName;
}
示例10: Browse
void Browse()
{
var dialog = new OpenFileDialog();
if (dialog.ShowDialog() ?? false) {
SvcUtilPath = dialog.FileName;
}
}
示例11: ButtonBase_OnClick
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
string file = ofd.FileName;
SendCommand(File.ReadAllText(file));
}
示例12: OpenFile
/// <summary>
/// Получеение открытого файла.
/// </summary>
/// <returns>Коллекцию</returns>
public static ProjectVm OpenFile()
{
var dialog = new OpenFileDialog
{
FileName = "ListOfTasks",
DefaultExt = ".xml",
Filter = "(*.xml, *.csv)|*.xml;*.csv"
};
var result = dialog.ShowDialog();
if (result != true) return null;
var tasks = ReadTasksFromFile(dialog.FileName);
if (tasks == null)
{
return null;
}
var projectVm = new ProjectVm
{
ListOfTasks = tasks
};
ConfigHelper.UpdateLastProject(new Project(dialog.FileName));
return projectVm;
}
示例13: HomeViewModel
/// <summary>
/// Initializes a new instance of the IntroductionViewModel class.
/// </summary>
public HomeViewModel(IConfigurationService configurationService)
{
_configurationService = configurationService;
selectedFile = _configurationService.IsFileLoaded() ? "hi" : "";
CreateNewFileCommand = new RelayCommand(() => {
var saveFileDialog = new SaveFileDialog();
saveFileDialog.AddExtension = true;
saveFileDialog.DefaultExt = "pktd";
saveFileDialog.Filter = "Parakeet File|*.pktd;*.pkd";
saveFileDialog.FileOk += SaveFileDialog_FileOk;
saveFileDialog.ShowDialog();
}, () => string.IsNullOrEmpty(SelectedFile));
OpenExistingFileCommand = new RelayCommand(() => {
var openFileDialog = new OpenFileDialog();
openFileDialog.AddExtension = true;
openFileDialog.DefaultExt = "pktd";
openFileDialog.Filter = "Parakeet File|*.pktd;*.pkd";
openFileDialog.Multiselect = false;
openFileDialog.FileOk += OpenFileDialog_FileOk;
openFileDialog.ShowDialog();
}, () => string.IsNullOrEmpty(SelectedFile));
}
示例14: ImportaSentencas
public void ImportaSentencas()
{
//List<string> mensagemLinha = new List<string>();
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Title = "";
openFileDialog.InitialDirectory = @"c:\temp";
openFileDialog.Filter = "Arquivos texto (*.txt)|*.txt| All files (*.*)|*.*";
openFileDialog.FilterIndex = 2;
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == true)
arquivo = openFileDialog.FileName;
if (String.IsNullOrEmpty(arquivo))
{
MessageBox.Show("Arquivo Invalido", "Alerta", MessageBoxButton.OK);
}
else
{
using (StreamReader texto = new StreamReader(arquivo))
{
while ((mensagem = texto.ReadLine()) != null)
{
//mensagemLinha.Add(mensagem);
CadastroSentenca.Adiciona(new Sentenca(0, mensagem, (bool)rbtn100.IsChecked));
}
}
}
Atualizar();
}
示例15: LoadImage
public void LoadImage()
{
var filedialog = new OpenFileDialog()
{
Multiselect = false
};
if (filedialog.ShowDialog() == true)
{
var temp = File.ReadAllBytes(filedialog.FileName);
var newtemp = new ushort[0x10000];
for (int i = 0; i < temp.Length; i++)
{
if (i % 2 == 0)
{
newtemp[i / 2] |= (ushort)(temp[i] << 8);
}
else
{
newtemp[i / 2] |= (ushort)(temp[i]);
}
}
App.CPU.SetMemory(newtemp);
}
}