当前位置: 首页>>代码示例>>C#>>正文


C# OpenFileDialog.ShowDialog方法代码示例

本文整理汇总了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);
                    }
                }
            }
        }
开发者ID:miaozhendaoren,项目名称:obd-express,代码行数:30,代码来源:PluginManager.xaml.cs

示例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();
            }
        }
开发者ID:giokats,项目名称:Projects-1,代码行数:35,代码来源:AccountsWindow.xaml.cs

示例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();
            }
        }
开发者ID:jsren,项目名称:DebugOS,代码行数:34,代码来源:AssemblyExplorer.xaml.cs

示例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();
            }
        }
开发者ID:Corprus,项目名称:swparse,代码行数:27,代码来源:MainWindow.xaml.cs

示例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);
            }
        }
开发者ID:Confirmit,项目名称:Students,代码行数:30,代码来源:AddNewPrinter.cs

示例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;
       }
 }
开发者ID:yuriik83,项目名称:OPC-UA-OOI,代码行数:35,代码来源:MainWindow.xaml.cs

示例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 "";
        }
开发者ID:maciejloz,项目名称:server_inz,代码行数:33,代码来源:UsableMethods.cs

示例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;
            }
        }
开发者ID:evkat,项目名称:diploma,代码行数:39,代码来源:LoadProjectCommand.cs

示例9: ExecuteOpenFileDialog

        public void ExecuteOpenFileDialog()
        {
            var dialog = new OpenFileDialog { InitialDirectory = _defaultPath };
            dialog.ShowDialog();

            SelectedPath = dialog.FileName;
        }
开发者ID:norrismiv,项目名称:launcher,代码行数:7,代码来源:OpenFIleDialogViewModel.cs

示例10: Browse

		void Browse()
		{
			var dialog = new OpenFileDialog();
			if (dialog.ShowDialog() ?? false) {
				SvcUtilPath = dialog.FileName;
			}
		}
开发者ID:Netring,项目名称:SharpDevelop,代码行数:7,代码来源:ServiceReferenceOptionsPanel.xaml.cs

示例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));
 }
开发者ID:sebingel,项目名称:SimpleNoisedTestClient,代码行数:7,代码来源:MainWindow.xaml.cs

示例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;
        }
开发者ID:serjebulavsky,项目名称:WPF_Test_Task,代码行数:32,代码来源:XmlWorker.cs

示例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));
        }
开发者ID:NeverOddOrEven,项目名称:Parakeet,代码行数:28,代码来源:HomeViewModel.cs

示例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();
        }
开发者ID:vanderleiarruda,项目名称:predicao-entropia-portugues,代码行数:32,代码来源:wCadastroSentencas.xaml.cs

示例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);
            }
        }
开发者ID:azunyuuuuuuu,项目名称:DCPU-16-Sharp,代码行数:27,代码来源:ShellViewModel.cs


注:本文中的Microsoft.Win32.OpenFileDialog.ShowDialog方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。