Scorpunduk

FileFolderOpenDialogs

Mar 24th, 2022
748
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15.  
  16. using Microsoft.Win32;
  17. using System.Windows.Forms;
  18.  
  19. namespace OpenFileOrFolder
  20. {
  21.     /// <summary>
  22.     /// Логика взаимодействия для MainWindow.xaml
  23.     /// </summary>
  24.     public partial class MainWindow : Window
  25.     {
  26.         public MainWindow()
  27.         {
  28.             InitializeComponent();
  29.         }
  30.  
  31.         private void selectFileBtn_Click(object sender, RoutedEventArgs e)
  32.         {
  33.             Microsoft.Win32.OpenFileDialog fileDialog = new Microsoft.Win32.OpenFileDialog();
  34.            
  35.             if(fileDialog.ShowDialog().Value != false)
  36.             {
  37.                 filePath.Text = fileDialog.FileName;
  38.             }
  39.         }
  40.  
  41.         // same result
  42.         private void selectWinFormsFileBtn_Click(object sender, RoutedEventArgs e)
  43.         {
  44.             System.Windows.Forms.OpenFileDialog fileDialog = new System.Windows.Forms.OpenFileDialog();
  45.  
  46.             if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  47.             {
  48.                 winFormsFilePath.Text = fileDialog.FileName;
  49.             }
  50.         }
  51.  
  52.         // ugly dialog, improved in .NET 3.0
  53.         private void selectFolderBtn_Click(object sender, RoutedEventArgs e)
  54.         {
  55.             FolderBrowserDialog folderDialog = new FolderBrowserDialog();
  56.            
  57.  
  58.             if(folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  59.             {
  60.                 folderPath.Text = folderDialog.SelectedPath;
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment