반응형
기존 폴더 선택
윈도우 탐색기 방식의 CommonOpenFileDialog
여기에 Windows API Code Pack 1.1을 다운로드 받아서 (view raw 누름 다운로드 시작)
Microsoft.WindowsAPICodePack.dll
Microsoft.WindowsAPICodePack.Shell.dll을 참조 하면 사용가능
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | using Microsoft.WindowsAPICodePack.Dialogs; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp8 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } // 기존 폴더 선택창 private void button1_Click(object sender, EventArgs e) { FolderBrowserDialog folderDlg = new FolderBrowserDialog(); folderDlg.ShowNewFolderButton = true; DialogResult result = folderDlg.ShowDialog(); if (result == DialogResult.OK) { textBox1.Text = folderDlg.SelectedPath; Environment.SpecialFolder root = folderDlg.RootFolder; } } // CommonOpenFileDialog 폴더 선택창 private void button2_Click(object sender, EventArgs e) { CommonOpenFileDialog dialog = new CommonOpenFileDialog(); dialog.InitialDirectory = textBox2.Text; dialog.IsFolderPicker = true; // true면 폴더 선택 false면 파일 선택 if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { textBox2.Text = dialog.FileName; } } } } | cs |
'프로그래밍 > C#' 카테고리의 다른 글
[C#] 둥근 버튼 (0) | 2019.01.12 |
---|---|
[C#]파일 확장자로 구분해서 image 저장 (0) | 2018.12.15 |
[C#]특정 폴더에 있는 모든 파일을 한 폴더에 Copy/Move (0) | 2018.11.26 |
[C#]소스 코드 접기, 펴기 (0) | 2018.11.09 |
[C#]Visual Studio 스크롤바 소스맵으로 보기 (0) | 2018.11.09 |