본문 바로가기

[C#] OpenFileDialog , 파일 오픈 팝업 만들기

I'm 영서 2022. 9. 14.
반응형

요론거 만드는 방법에 대한 정리

완성품..

코드는 아래와 같다.

 

ImageCodecInfo 에서 인코더 정보를 필터에 추가하고, Dialog를 열어주면 끝..!

 

가져온 fileName을 가지고 뭔가 작업을 해주면 된다.

 

MessageBox.Show("Load버튼 클릭");

OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "";
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
string sep = string.Empty;
string filter = string.Empty;
foreach (var c in codecs)
{
    string codecName = c.CodecName.Substring(8).Replace("Codec", "Files").Trim();
    filter += String.Format("{0}{1}{2} ({3})|{3}", dialog.Filter, sep, codecName, c.FilenameExtension)+"|";


}

dialog.DefaultExt = ".png"; // Default file extension 
dialog.Multiselect = true;

dialog.Filter = filter+ String.Format("{0}{1}{2} ({3})|{3}", dialog.Filter, sep, "All Files", "*.*");
Nullable<bool> result = dialog.ShowDialog();

if (result == true)
{

    foreach(string fileName in dialog.FileNames)
    {
    }
}
반응형

'Study > C#' 카테고리의 다른 글

[C#] Singleton 디자인 패턴 구현방법  (0) 2023.01.05
[C#] Property  (0) 2022.09.16
[C#] WPF DevExpress TableView MutliSelection  (0) 2022.09.13
[C#] Dictionary 사용하기  (0) 2022.09.05
[C#] 중복 실행 방지  (0) 2022.08.16

댓글