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


C# Win32.OpenFileDialog类代码示例

本文整理汇总了C#中Microsoft.Win32.OpenFileDialog的典型用法代码示例。如果您正苦于以下问题:C# OpenFileDialog类的具体用法?C# OpenFileDialog怎么用?C# OpenFileDialog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OpenFileDialog类属于Microsoft.Win32命名空间,在下文中一共展示了OpenFileDialog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Browse

        public BrowseResult Browse(BrowseParams browseParams)
        {
            if(browseParams==null) browseParams = new BrowseParams();

            FileDialog dialog = new OpenFileDialog();
            return OpenDialog(dialog, browseParams);
        }
开发者ID:vansickle,项目名称:dbexplorer,代码行数:7,代码来源:BrowseFileService.cs

示例2: Merge

		public void Merge()
		{
			var openDialog = new OpenFileDialog()
			{
				Filter = "firesec2 files|*.fscp",
				DefaultExt = "firesec2 files|*.fscp"
			};
			if (openDialog.ShowDialog().Value)
			{
				ServiceFactory.Events.GetEvent<ConfigurationClosedEvent>().Publish(null);
				ZipConfigActualizeHelper.Actualize(openDialog.FileName, false);
				var folderName = AppDataFolderHelper.GetLocalFolder("Administrator/MergeConfiguration");
				var configFileName = Path.Combine(folderName, "Config.fscp");
				if (Directory.Exists(folderName))
					Directory.Delete(folderName, true);
				Directory.CreateDirectory(folderName);
				File.Copy(openDialog.FileName, configFileName);
				LoadFromZipFile(configFileName);
				ServiceFactory.ContentService.Invalidate();

				FiresecManager.UpdateConfiguration();

				ServiceFactory.Events.GetEvent<ConfigurationChangedEvent>().Publish(null);
				ServiceFactory.Layout.Close();
				if (ApplicationService.Modules.Any(x => x.Name == "Устройства, Зоны, Направления"))
					ServiceFactory.Events.GetEvent<ShowDeviceEvent>().Publish(Guid.Empty);
				else if (ApplicationService.Modules.Any(x => x.Name == "Групповой контроллер"))
					ServiceFactory.Events.GetEvent<ShowXDeviceEvent>().Publish(Guid.Empty);

				ServiceFactory.SaveService.FSChanged = true;
				ServiceFactory.SaveService.PlansChanged = true;
				ServiceFactory.SaveService.GKChanged = true;
				ServiceFactory.Layout.ShowFooter(null);
			}
		}
开发者ID:saeednazari,项目名称:Rubezh,代码行数:35,代码来源:MergeConfigurationHelper.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: 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

示例5: 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

示例6: GetImageKeyAsync

        /// <inheritdoc/>
        public async Task<string> GetImageKeyAsync()
        {
            try
            {
                var dlg = new OpenFileDialog()
                {
                    Filter = "All (*.*)|*.*",
                    FilterIndex = 0,
                    FileName = ""
                };

                if (dlg.ShowDialog(_serviceProvider.GetService<MainWindow>()) == true)
                {
                    var path = dlg.FileName;
                    var bytes = System.IO.File.ReadAllBytes(path);
                    var key = _serviceProvider.GetService<ProjectEditor>().Project.AddImageFromFile(path, bytes);
                    return await Task.Run(() => key);
                }
            }
            catch (Exception ex)
            {
                _serviceProvider.GetService<ILog>().LogError($"{ex.Message}{Environment.NewLine}{ex.StackTrace}");
            }

            return null;
        }
开发者ID:Core2D,项目名称:Core2D,代码行数:27,代码来源:Win32ImageImporter.cs

示例7: GetLayout

        public override InteriorField[,] GetLayout()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.DefaultExt = "txt";
            DirectoryInfo currentDir = new DirectoryInfo(Environment.CurrentDirectory);
            openFileDialog.InitialDirectory = (currentDir.EnumerateDirectories().FirstOrDefault(d => d.Name == DataSubdirName) ?? currentDir).FullName;
            if (openFileDialog.ShowDialog().GetValueOrDefault())
            {
                this.LayoutIdentifier = openFileDialog.FileName;
                using (StreamReader readLines = new StreamReader(openFileDialog.OpenFile()))
                {
                    List<List<InteriorField>> layout = readLines
                        .ReadToEnd()
                        .Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
                        .Select(s => s
                            .Select(c => this.CreateField(c)).ToList()).ToList();

                    int columnsCount = layout.Max(l => l.Count);
                    InteriorField[,] result = new InteriorField[layout.Count, columnsCount];
                    for (int row = 0; row < layout.Count; row++)
                    {
                        for (int col = 0; col < layout[row].Count; col++)
                        {
                            result[row, col] = layout[row][col];
                        }
                    }
                    return result;
                }
            }
            else
            {
                return null;
            }
        }
开发者ID:blattodephobia,项目名称:ExperianOfficeArangement,代码行数:34,代码来源:FileLoadInteriorLayoutFactory.cs

示例8: OpenFile

        public static MEFile OpenFile()
        {
            string content = "";
            // Create OpenFileDialog
            OpenFileDialog dlg = new OpenFileDialog();

            // Set filter for file extension and default file extension
            dlg.DefaultExt = ".txt";
            dlg.Filter = TextFileFilter;

            // Display OpenFileDialog by calling ShowDialog method
            bool? result = dlg.ShowDialog();

            // Get the selected file name and display in a TextBox
            if (result == true)
            {
                content = File.ReadAllText(dlg.FileName);
                string FileName = Path.GetFileNameWithoutExtension(dlg.SafeFileName);
                string Extension = Path.GetExtension(dlg.SafeFileName);
                return new MEFile(FileName, Extension, content, dlg.FileName);
            }
            else
            {
                return MEFile.ERROR_ME_FILE;
            }

            throw new NotImplementedException();
        }
开发者ID:EverlessDrop41,项目名称:ModernEdit,代码行数:28,代码来源:FileUtils.cs

示例9: 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:CDMirel,项目名称:obd-express,代码行数:30,代码来源:PluginManager.xaml.cs

示例10: 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

示例11: OpenCommandHandler

        private void OpenCommandHandler(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.FileName = "Document"; // Default file name
            dlg.DefaultExt = ".txt"; // Default file extension
            dlg.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension

            // Show open file dialog box
            Nullable<bool> result = dlg.ShowDialog();

            // Process open file dialog box results
            if (result == true)
            {
                // Open document
                string filename = dlg.FileName;

                TextRange range;
                FileStream fStream;
                if (File.Exists(filename))
                {
                    tabControl1.SelectedIndex = 1;
                    range = new TextRange(rtb1.Document.ContentStart, rtb1.Document.ContentEnd);
                    fStream = new FileStream(filename, FileMode.OpenOrCreate);
                    range.Load(fStream, DataFormats.Text);
                    fStream.Close();                    
                }
                FormatWholeDocument();
            }
        }
开发者ID:anujgeek,项目名称:Microprocessor8085Simulator,代码行数:29,代码来源:Commands.cs

示例12: ExecuteOpenFileDialog

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

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

示例13: 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

示例14: Browse

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

示例15: OpenCommand_Execute

        private void OpenCommand_Execute(object sender, ExecutedRoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == true)
            {
                ellipses.Clear();

                StreamReader sr = new StreamReader(ofd.FileName);
                while (!sr.EndOfStream)
                {
                    String[] g = sr.ReadLine().Split(' ');
                    Circle circle = new Circle() { R = double.Parse(g[0]), X = double.Parse(g[1]), Y = double.Parse(g[2]) };
                    ellipses.Add(circle);
                }
                sr.Close();

                vd = new VD<Circle, DeloneCircle>(ellipses[0], ellipses[1], null);
                for (int i = 2; i < ellipses.Count; i++)
                    vd.Insert(ellipses[i]);

                if (vd != null)
                    BuildTriples(vd.NextTriple(vd.NullTriple), gg_triples, true);
                else
                    gg_triples.Children.Clear();
                triple = vd.NextTriple(vd.NullTriple);
            }
        }
开发者ID:Ring-r,项目名称:opt,代码行数:27,代码来源:MainWindow.xaml.cs


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