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


C# OpenFileDialog.ShowDialog方法代码示例

本文整理汇总了C#中System.Windows.Controls.OpenFileDialog.ShowDialog方法的典型用法代码示例。如果您正苦于以下问题:C# OpenFileDialog.ShowDialog方法的具体用法?C# OpenFileDialog.ShowDialog怎么用?C# OpenFileDialog.ShowDialog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.OpenFileDialog的用法示例。


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

示例1: OpenClick

 private void OpenClick(object sender, RoutedEventArgs e)
 {
     OpenFileDialog openDialog = new OpenFileDialog();
     openDialog.Filter = "clients.json|clients.json"; //http://www.wpf-tutorial.com/dialogs/the-openfiledialog/
     openDialog.ShowDialog();
     string ClientFile = openDialog.FileName;
     openDialog.Filter = "workers.json|workers.json";
     openDialog.ShowDialog();
     string WorkerFile = openDialog.FileName;
     if (ClientFile == "" || WorkerFile == "") { MessageBox.Show("Select both files!"); return; }
     try
     {
         Clients.RemoveAll(t => t.Name == t.Name);
         Clients.AddRange(JsonConvert.DeserializeObject<List<Person>>(File.ReadAllText(ClientFile)));
         ClientData.Items.Refresh();
         ClientGrid.IsEnabled = true;
         Workers.RemoveAll(t => 1 == 1);
         Workers.AddRange(JsonConvert.DeserializeObject<List<Person>>(File.ReadAllText(WorkerFile)));
         WorkerData.Items.Refresh();
         WorkerGrid.IsEnabled = true;
     }
     catch (Exception exc)
     {
         MessageBox.Show("Something went wrong! " + exc.Message);
     }
 }
开发者ID:edgars-supe,项目名称:dotnet-hw3,代码行数:26,代码来源:MainWindow.xaml.cs

示例2: Button3_Click

        private void Button3_Click(object sender, RoutedEventArgs eArgs)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
            if (dlg.ShowDialog() != true)
                return;

            var txtLines = System.IO.File.ReadAllLines(dlg.FileName);
            var pts = new ObservableCollection<NehPoint>();

            var idexFile = Path.ChangeExtension(dlg.FileName, ".idx");
            using (var idexStream = new FileStream(idexFile, FileMode.Create))
            {
                using (var gsiWriter = new IDEXFileWriter(idexStream))
                {
                    foreach (var ln in txtLines)
                    {
                        if (!string.IsNullOrEmpty(ln.Trim())) {
                        var pt = new NehPoint(ln);
                        gsiWriter.AddPoint(pt.Id, pt.E, pt.N, pt.H, null);
                        pts.Add(pt);
                        }
                    }
                }
            }
            PtsGrid.ItemsSource = pts;
            MessageBox.Show("Saved to: \r\n" + idexFile);
        }
开发者ID:kubaszostak,项目名称:coordinatus,代码行数:28,代码来源:MainWindow.xaml.cs

示例3: ImportImageButtonClick

		private void ImportImageButtonClick(object sender, RoutedEventArgs e)
		{
			OpenFileDialog openFileDialog = new OpenFileDialog();
#if WPF
			openFileDialog.Filter = "Image Files (*.png, *.jpg, *.bmp)|*.png;*.jpg;*.bmp";
#else
			openFileDialog.Filter = "Image Files (*.png, *.jpg)|*.png;*.jpg";
#endif
			bool? dialogResult = openFileDialog.ShowDialog();
			if (dialogResult.HasValue && dialogResult.Value == true)
			{
				Image image = new Image();
#if WPF
				image.Source = new BitmapImage(new Uri(openFileDialog.FileName, UriKind.Absolute));
#else
					using (var fileOpenRead = openFileDialog.File.OpenRead())
					{
						BitmapImage bitmap = new BitmapImage();
						bitmap.SetSource(fileOpenRead);
						image.Source = bitmap;
					}
#endif
				Viewbox viewBox = new Viewbox() { Stretch = Stretch.Fill, Margin = new Thickness(-4) };
				viewBox.Child = image;
				RadDiagramShape imageShape = new RadDiagramShape()
				{
					Content = viewBox
				};
				this.diagram.Items.Add(imageShape);
			}
		}
开发者ID:netintellect,项目名称:PluralsightSpaJumpStartFinal,代码行数:31,代码来源:Example.xaml.cs

示例4: BtnNodefileSel_OnClick

        /// <summary>
        /// Get the nodes from the selected text file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnNodefileSel_OnClick(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
            //openFileDialog.InitialDirectory = citiesIn.filepath;
            if (openFileDialog.ShowDialog() == true)
            {
                txtboxNodefile.Text = @"...\" + openFileDialog.SafeFileName;
                citiesIn.filepath = openFileDialog.FileName;
            }

            // set the value of the combobox
            nodelist = citiesIn.GetCitieses();
            maxNumofCities = nodelist.Count;
            List<string> citynames = nodelist.Select(cityNode => cityNode.city).ToList();
            comboboxStartCity.ItemsSource = citynames;
            comboboxStartCity.SelectedIndex = 0;
            lboxManualSelectNodes.ItemsSource = citynames;

            if (RandomNodeSelect.IsChecked == true)
                lboxManualSelectNodes.IsEnabled = false;
            else
                lboxManualSelectNodes.IsEnabled = true;

            // draw the circles
            _drawlines(citylisttodraw);
        }
开发者ID:KSWestfall,项目名称:csharp-traveling-salesman,代码行数:32,代码来源:MainWindow.xaml.cs

示例5: InitGamePath

        /// <summary>
        /// Initializes the gamePath if not specefied defines new one
        /// </summary>
        private void InitGamePath()
        {
            if (AppSettings.getPropertyValue<string>("GamePath").Length > 2 || Directory.Exists(AppSettings.getPropertyValue<string>("GamePath")) == false)
            {
                RegistryKey regKey = Registry.CurrentUser;
                regKey = regKey.OpenSubKey(@"Software\Valve\Steam");

                if (regKey != null && regKey.GetValue("SteamPath") != null && Directory.Exists(regKey.GetValue("SteamPath").ToString().Replace("/", "\\") + "\\steamapps\\common\\Arma 3"))
                {
                    AppSettings.setProperty("GamePath", regKey.GetValue("SteamPath").ToString().Replace("/", "\\") + "\\steamapps\\common\\Arma 3");
                    AppSettings.SaveAsync();
                    return;
                }
                else
                    if (MessageBox.Show("Unable to locate \"arma3.exe\"!" + Environment.NewLine + "Do you want so specify it?", "Installation not found!", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.Yes)
                    {
                        OpenFileDialog ofd = new OpenFileDialog();
                        ofd.Filter = "Arma 3|arma3.exe";

                        if (ofd.ShowDialog() == true)
                        {
                            AppSettings.setProperty("GamePath", ofd.FileName.Replace("\\" + ofd.FileName.Split('\\')[ofd.FileName.Split('\\').Length - 1], ""));
                            AppSettings.SaveAsync();
                        }
                        else
                            Environment.Exit(1223);
                    }
                    else
                        Environment.Exit(1223);
            }
        }
开发者ID:Exthero,项目名称:LIEL,代码行数:34,代码来源:MainWindow.xaml.cs

示例6: btnRun_Click

		private void btnRun_Click(object sender, RoutedEventArgs e)
		{
			OpenFileDialog dlg = new OpenFileDialog();
			dlg.Filter = "Programs|*.exe|All files|*.*";
			dlg.DefaultExt = ".exe";
			if (!(dlg.ShowDialog() ?? false))
				return;
			string path = dlg.FileName;

			// remove UI before disposing profiler
			//this.timeLine.ValuesList.Clear();
			if (this.provider != null)
				this.provider.Close();

			if (this.profiler != null)
				this.profiler.Dispose();
			
			string pathToDb = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(typeof(Profiler.Controller.Profiler).Assembly.Location), "output.sdps");
			if (File.Exists(pathToDb))
				File.Delete(pathToDb);
			
			this.database = new TempFileDatabase();
			
			this.profiler = new Profiler.Controller.Profiler(path, database.GetWriter(), new ProfilerOptions());
			profiler.RegisterFailed += delegate { MessageBox.Show("register failed"); };
			profiler.DeregisterFailed += delegate { MessageBox.Show("deregister failed"); };

			this.profiler.OutputUpdated += profiler_OutputUpdated;
			this.profiler.SessionEnded += profiler_SessionEnded;

			this.profiler.Start();

			this.btnRun.IsEnabled = false;
			this.btnStop.IsEnabled = true;
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:35,代码来源:Window1.xaml.cs

示例7: LoadImage

        public void LoadImage()
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Bitmap Image (.bmp)|*.bmp|PNG Image (.png)|*.png|JPEG Image (.jpeg)|*.jpeg|JPG Image (.jpg)|*.jpg";

            bool? result = ofd.ShowDialog();

            string fileName = "";
            if (result != null)
                fileName = ofd.FileName;

            if (fileName == "")
                return;

            canvas.Children.Clear();
            BitmapImage image;
            using (FileStream stream = new FileStream(fileName, FileMode.Open))
            {
                stream.Position = 0;
                image = new BitmapImage();
                image.BeginInit();
                image.StreamSource = stream;
                image.CacheOption = BitmapCacheOption.OnLoad;
                image.EndInit();
            }
            canvas.Background = new ImageBrush(image);
        }
开发者ID:Exellion,项目名称:Paint,代码行数:27,代码来源:ImageHandler.cs

示例8: OpenFile

        /**
         * <summary>Zeigt OpenFileDialog an</summary>
         *
         * <remarks>Beate, 09.10.2013.</remarks>
         */
        private static string OpenFile()
        {
            string[] allfiles = { };
            string filename = string.Empty;
            string path = string.Empty;
            List<string> filenameOnly = new List<string>();
            OpenFileDialog inputDlg = new OpenFileDialog();
            inputDlg.Multiselect = true;
            inputDlg.InitialDirectory = @"";
            inputDlg.Filter = "Xmascup Competitor Dateien|Competitor*.xml";

            if (inputDlg.ShowDialog().Value)
            {
                allfiles = inputDlg.FileNames;
                foreach (string s in allfiles)
                {
                    filename = System.IO.Path.GetFileName(s);
                    path = System.IO.Path.GetDirectoryName(s);
                    filenameOnly.Add(filename);

                }

                MessageBox.Show("Eingabe: " + filename,
                    "Xmascup Dateiauswahl");
                return allfiles[0].ToString();
            }
            else
            {
                MessageBox.Show("Keine Datei ausgewählt !!",
                     "Xmascup Dateiauswahl");
                return "keine Auswahl getroffen";
            }
        }
开发者ID:hrherbie,项目名称:Xmascup,代码行数:38,代码来源:MainWindow.xaml.cs

示例9: SetMode

 private void SetMode()
 {
     if(IsFileSelector)
     {
         ButtonText = "\uF15C";
         ButtonCommand = new RelayCommand(() => 
         {
             var dlg = new OpenFileDialog();
             if (dlg.ShowDialog() == true)
             {
                 ConfigItemValue = dlg.FileName;
             }
         }, true);
     }
     else
     {
         ButtonText = "\uF07C";
         ButtonCommand = new RelayCommand(() =>
         {
             var dlg = new System.Windows.Forms.FolderBrowserDialog();
             dlg.ShowNewFolderButton = true;
             dlg.ShowDialog();
             if (!String.IsNullOrEmpty(dlg.SelectedPath))
             {
                 ConfigItemValue = dlg.SelectedPath;
             }
         }, true);
     }
 }
开发者ID:llenroc,项目名称:sharpDox,代码行数:29,代码来源:ConfigFileSystemControl.xaml.cs

示例10: Button_Click_1

        //导入“1300000	"北京市"	"联通"”文本格式数据
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "文本文件|*.txt";
            if (ofd.ShowDialog() == false)
            {
                return;
            }

            string[] lines = File.ReadLines(ofd.FileName, Encoding.Default).ToArray();

            for (int i = 1; i < lines.Count(); i++)
            {
                string line = lines[i];
                string[] str = line.Split('\t');
                string startTeLNum = str[0];
                string city = str[1];
                city = city.Trim('"');
                string telType = str[2];
                telType = telType.Trim('"');
                SqlHelper.ExecuteQuery(@"Insert into T_TelNum(StartTelNum,TelType,TelArea) 
                    values(@StartTelNum,@TelType,@TelArea)",
                    new SqlParameter("@StartTelNum", startTeLNum),
                new SqlParameter("@TelType", telType),
                new SqlParameter("@TelArea", city));
            }
            MessageBox.Show("导入成功!"+lines.Count()+"条数据");
        }
开发者ID:kai2008009,项目名称:ADO.NET,代码行数:29,代码来源:导入数据.xaml.cs

示例11: button1_Click

 private void button1_Click(object sender, RoutedEventArgs e)
 {
     OpenFileDialog openfiledialog = new OpenFileDialog();
     openfiledialog.ShowDialog();
     //if(openfiledialog.FileOk)
        // System.IO.Stream fileStream = openfiledialog.FileOk;
 }
开发者ID:hkalyan,项目名称:WpfApplication1,代码行数:7,代码来源:MainWindow.xaml.cs

示例12: btn_insert_Click

        //导入“张三|123”文本格式数据
        private void btn_insert_Click(object sender, RoutedEventArgs e)
        {
            //打开文本
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "文本文件|*.txt";
            if (ofd.ShowDialog() != true)
            {
                return;
            }
            string filename = ofd.FileName;

            //把文件一次读取到string集合中
            IEnumerable<string> lines = File.ReadLines(filename, Encoding.Default);

            foreach (string line in lines)
            {
                string[] segs = line.Split('|', ' ');
                string name = segs[0];
                string age = segs[1];
                SqlHelper.ExecuteQuery("insert into custome(Name,Age)values(@Name,@Age)",
                    new SqlParameter("@Name", name),
                    new SqlParameter("@Age", Convert.ToInt32(age)));
            }
            MessageBox.Show("导入成功" + lines.Count() + "条数据!");
        }
开发者ID:kai2008009,项目名称:ADO.NET,代码行数:26,代码来源:导入数据.xaml.cs

示例13: EjectButton_Click

        private void EjectButton_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog { Title = "Select an audio file (wma, mp3, ...etc.) or video file..." };
            if (dialog.ShowDialog() == true)
            {
                lock (lockAudio)
                {
                    if (audioPlayer != null)
                    {
                        audioPlayer.Close();
                        audioPlayer = null;
                    }

                    if (fileStream != null)
                    {
                        fileStream.Close();
                    }

                    // Ask the user for a video or audio file to play
                    fileStream = new NativeFileStream(dialog.FileName, NativeFileMode.Open, NativeFileAccess.Read);

                    audioPlayer = new AudioPlayer(xaudio2, fileStream);

                    FilePathTextBox.Text = dialog.FileName;
                    SoundProgressBar.Maximum = audioPlayer.Duration.TotalSeconds;
                    SoundProgressBar.Value = 0;

                    // Auto-play
                    audioPlayer.Play();
                }
            }
        }
开发者ID:Nezz,项目名称:SharpDX,代码行数:32,代码来源:MainWindow.xaml.cs

示例14: btnBrowse_Click

        private void btnBrowse_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog();

            if (dialog.ShowDialog() == true)
                SetPreviewImage(dialog.FileName);
        }
开发者ID:Wezthal,项目名称:MapEditor,代码行数:7,代码来源:TileSetEditor.xaml.cs

示例15: OpenOnExecuted

        // �����Ϳ��� �̺�Ʈ �ڵ鷯 (���� IO�κ�)
        // ������ ������� ���̴� Deserialize�� Serialize �κ�
        void OpenOnExecuted(object sender, ExecutedRoutedEventArgs args)
        {
            OpenFileDialog dlg = new OpenFileDialog();    // ���Ͽ��� ���̾�α� ��ü ����
            dlg.Filter = strFilter;                                   // ǥ�õǴ� �������� ���� (�������ĺκ�)
            Person pers;                                            // PersonŬ���� ��ü ����

            if ((bool)dlg.ShowDialog(this))                      // ���Ͽ��� ���̾�αװ� ����������?
            {
                try
                {
                    // �����̸� ���ڿ��� �д� ��Ʈ�� ���� ��ü ����
                    StreamReader reader = new StreamReader(dlg.FileName);
                    // ��Ʈ������ ��ü�� �籸�� �ؼ� Person ��ü�� ����
                    pers = (Person) xml.Deserialize(reader);
                    reader.Close();
                }
                catch (Exception exc)
                {
                    MessageBox.Show("������ �����ھ�� ��  _�� : " + exc.Message,
                                    Title, MessageBoxButton.OK,  MessageBoxImage.Exclamation);
                    return;
                }
                // DataContext�� ��Ұ� ���ε��� ���Ǵ� ������ �ҽ��� ���� ���� �� ��� ��
                // ���ε��� ��Ÿ Ư���� �θ� ��ҷκ��� ��� �� �� �ֵ��� �ϴ� ����.
                pnlPerson.DataContext = pers;
            }
        }
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:29,代码来源:SingleRecordDataEntry.cs


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