Last active
December 18, 2015 21:29
-
-
Save ochilab/5847970 to your computer and use it in GitHub Desktop.
オープンファイルダイアログを利用したファイル選択のサンプルです。このサンプルでは、tiffファイルを対象としています。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string tiffFileName; | |
//OpenFileDialogクラスのインスタンスを作成 | |
OpenFileDialog ofd = new OpenFileDialog(); | |
ofd.InitialDirectory = @"C:\"; | |
//[ファイルの種類]に表示される選択肢を指定する | |
//指定しないとすべてのファイルが表示される | |
ofd.Filter = | |
"tifファイル(*.tif)|*.tif"; | |
//[ファイルの種類]ではじめに | |
//「すべてのファイル」が選択されているようにする | |
ofd.FilterIndex = 2; | |
//タイトルを設定する | |
ofd.Title = "開くファイルを選択してください"; | |
//ダイアログボックスを閉じる前に現在のディレクトリを復元するようにする | |
ofd.RestoreDirectory = true; | |
//ダイアログを表示する | |
if (ofd.ShowDialog() == DialogResult.OK) { | |
//OKボタンがクリックされたとき | |
tiffFileName = ofd.FileName; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment