主婦と.NETと犬のぶろぐ

奥様 と プログラム と お犬様 の 楽しい日常

目次

Blog 利用状況

ニュース

書庫

日記カテゴリ

OpenFileDialog(System.Windows.Forms.OpenFileDialog)

いつもちょっと疑問に思うこと。FilterIndex の指定がなんかへん。なんで 1 からなんだ?なんで 0 を指定しても 1 と同じ動きすんだ?

名前のせいなのか、勘違いされやすいのが RestoreDirectory。

# 追記(ワタシも勘違いしてました...orz)
# コメント及びコメント欄を参照ください。

一応書いておくと、たとえば InitialDirectory を デスクトップにしたとします。
そんで ユーザーがボタンを押すなどして OpenFileDialog.ShowDialog した後に、
ユーザーが \...\デスクトップ\ふじこ\ひるね フォルダに移動して、
ユーザーが \...\デスクトップ\ふじこ\ひるね\あくび.TXT を選択して [開く]を押下します。
一回目の操作はコレで終わり。
二回目、ユーザーが再度ボタンを押すなどして OpenFileDialog.ShowDialog した時、
InitialDirectory の デスクトップでなくて、\...\デスクトップ\ふじこ\ひるね を開く
というだけのもの。

# ↑ これは、FileName プロパティによるものだそうです。
# FileName に 値がセットしてある場合、InitialDirectory は無視され、初期ディレクトリは FileName のファイルがあるディレクトリになるそうです。
# RestoreDirectory = False は、System.Environment.CurrentDirectory が 上記例だと \...\デスクトップ\ふじこ\ひるね になり、
# RestoreDirectory = True は CurrentDirectory はいったん変わるものの、ShowDialog  から抜けると CurrentDirectory の元の値を復帰します。

削除しても復元してくれるとかそんなんじゃないす。

■参考文献
OpenFileDialog クラス
OpenFileDialog コンポーネント (Windows フォーム)

■実行画像
ごてごてな OpenFileDialog
NumericUpDown

Public Class OpenFileDialogTest

Private Sub OpenFileDialogTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load With Me.OpenFileDialog1 ' 既定:True .AddExtension = True ' 存在しないファイルを指定した場合に警告を出す(既定:True) .CheckFileExists = True ' 存在しないパスを指定した場合に警告を出す(既定:True) .CheckPathExists = True ' 拡張子が指定されない場合の既定の拡張子を指定 .DefaultExt = "txt" ' ショートカットを指定した場合、ショートカット自体を選択するか ' 実体を選択するかを指定(既定:True) .DereferenceLinks = True ' 選択されているファイル名 .FileName = "" ' [ファイルの種類] ボックスに表示される選択肢 .Filter = "テキスト(*.txt)|*.txt|イメージ(*.bmp;*.jpg;*.png)|*.bmp;*.jpg;*.png|ふじこえでん(*.fujiko.eden)|*.fujiko.eden" ' Filter でいくつか指定した時にどれを最初に表示するか(これだとイメージが表示) .FilterIndex = 2 ' 既定で選択されてるディレクトリ .InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) ' 複数選択を許可するか否かの指定(既定:False) .Multiselect = False ' [読み取り専用ファイルとして開く]チェックボックスを表示するか否か(既定:False) .ShowReadOnly = True ' [読み取り専用ファイルとして開く]チェックボックスのチェックの状態(既定:False) .ReadOnlyChecked = True ' Environment.CurrentDirectory をユーザーが指定した場所に変更するか否か(既定:False) .RestoreDirectory = True ' ヘルプボタンを表示するか否か(既定:False) .ShowHelp = True ' ダイアログ ボックスが複数のファイル名拡張子をを受け入れるか否か(既定:False) ' Filter で指定した *.fujiko.eden で、hoge.fujiko.eden の拡張子を .eden とするか .fujiko.eden とするか .SupportMultiDottedExtensions = True ' タイトル .Title = "ふぁいるをしていしてね" ' 有効な Win32 ファイル名だけを受け入れるかどうか(既定:True) .ValidateNames = True End With End Sub
Private Sub OpenFileDialogTest_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.DoubleClick ' Form をダブルクリックして OpenFileDialog を開く Dim result As DialogResult = Me.OpenFileDialog1.ShowDialog(Me) End Sub
' OpenFileDialog で 開くボタン押下時 Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk Dim filePath As String = Me.OpenFileDialog1.FileName Dim ext As String = System.IO.Path.GetExtension(filePath).ToLower() Dim st As System.IO.Stream = Me.OpenFileDialog1.OpenFile()
Me.ClearControls() Dim sz As Size = New Size(250, 250) Dim lc As Point = New Point(10, 10) If ext.Contains("bmp") OrElse ext.Contains("jpg") OrElse ext.Contains("png") Then ' 画像だったら PictureBox に表示 Dim pic As PictureBox = New PictureBox() pic.Size = sz pic.SizeMode = PictureBoxSizeMode.Zoom pic.Location = lc pic.Image = Bitmap.FromStream(st) Me.Controls.Add(pic) Else ' 画像以外だったら TextBox に表示 Dim txt As TextBox = New TextBox() txt.Multiline = True txt.ScrollBars = ScrollBars.Both txt.Size = sz txt.Location = lc txt.Text = New System.IO.StreamReader(st, System.Text.Encoding.Default).ReadToEnd Me.Controls.Add(txt) End If End Sub
' OpenFileDialog で ヘルプボタン押下時 Private Sub OpenFileDialog1_HelpRequest(ByVal sender As Object, ByVal e As System.EventArgs) Handles OpenFileDialog1.HelpRequest Dim ofd As OpenFileDialog = DirectCast(sender, OpenFileDialog) MessageBox.Show(ofd.Title) ' OpenFileDialog の Title をメッセージ表示 End Sub
Private Sub ClearControls() For Each ctrl As Control In Me.Controls Me.Controls.Remove(ctrl) ctrl.Dispose() Next End Sub End Class

投稿日時 : 2007年3月1日 11:55

Feedback

# re: OpenFileDialog(System.Windows.Forms.OpenFileDialog) 2007/03/01 12:00 επιστημη

コードそっちのけでふじこのサムネイルに見入っちゃうんですケド
# それはそれで善し ^^;

# re: OpenFileDialog(System.Windows.Forms.OpenFileDialog) 2007/03/01 12:40 渋木宏明(ひどり)

>二回目、ユーザーが再度ボタンを押すなどして...というだけのもの。

「再度xxxフォルダを開く」というのは結果であって、それよりももっと重要な役割があります。

# re: OpenFileDialog(System.Windows.Forms.OpenFileDialog) 2007/03/01 12:52 なおこ(・∀・)

>> えぴさん
(^^)

>> ひどりさん
> それよりももっと重要な役割があります。
何だろう...教えてください~!!

# re: OpenFileDialog(System.Windows.Forms.OpenFileDialog) 2007/03/01 12:55 シャノン

FilterIndex が1からなのは、Win32 のコモンダイアログを引きずっているせいですね。
FilterIndex = 0 は、ユーザ定義のカスタムフィルタを表します。
この仕様は難解でよくわからん。
詳しくは Win32 API の OPENFILENAME 構造体を参照。

> 名前のせいなのか、勘違いされやすいのが RestoreDirectory。

違います。
RestoreDirectory = false だと、ファイルを選んだ時に、カレントディレクトリ(Environment.CurrentDirectory)が、そのファイルのあるディレクトリになってしまいます。
RestoreDirectory = true だと、それが阻止されます。

InitialDirectory が無視されるのは、FileName に1回目のファイル名が残っているから。
FileName プロパティが設定されていると、InitialDirectory は無視され、初期ディレクトリはそのファイルがあるディレクトリになります。

# re: OpenFileDialog(System.Windows.Forms.OpenFileDialog) 2007/03/01 13:28 なおこ(・∀・)

>> シャノンさん
おぉ。。。いつもありがとうございます(*_ _)
RestoreDirectory についての記述を
シャノンさんのコメントを元に修正しました。

# re: OpenFileDialog(System.Windows.Forms.OpenFileDialog) 2007/03/02 14:11 渋木宏明(ひどり)

>RestoreDirectory = true だと、それが阻止されます。

阻止はされなくて、一旦そのディレクトリにカレントディレクトリが移されるけど、ShowDialog() から抜ける時に「復帰」さえます。

# re: OpenFileDialog(System.Windows.Forms.OpenFileDialog) 2007/03/02 20:23 なおこ(・∀・)

>> ひどりさん
ありがとうございます。

っていうか RestoreDirectory ...(@_@;)
MSDN のあの説明じゃそこまで読み取れない...

# SaveFileDialog(System.Windows.Forms.SaveFileDialog) 2007/03/26 10:02 主婦と.NETと犬のぶろぐ

SaveFileDialog(System.Windows.Forms.SaveFileDialog)

# FoPautineBF 2014/08/28 8:12 http://crorkz.com/

2VmzhS Thanks for another magnificent article. Where else could anyone get that type of info in such an ideal way of writing? I have a presentation next week, and I am on the look for such info.

# re: INCREASEUSERVA 2016/12/10 14:04 meadc

http://www.coach-sunglasses.co/ coach sunglasses
http://www.raybansunglasses.com.au ray-ban sunglasses

# RZCJGQitlQ 2018/12/21 12:23 https://www.suba.me/

7sKfBh to my friends. I am confident they will be

# aXziatgQZiLFwQ 2018/12/24 23:28 https://preview.tinyurl.com/ydapfx9p

Im grateful for the article post.Thanks Again. Much obliged.

# kErcerRGNNydjTuowsA 2018/12/26 23:37 http://parents-teachers.com/lib/topframe2014.php?g

Simply wanna comment that you have a very decent web site , I the style it really stands out.

# saWAGczZeIWSHO 2018/12/27 7:57 http://www.224631.com/home.php?mod=space&uid=5

This is a really good tip particularly to those fresh to the blogosphere. Brief but very accurate info Thanks for sharing this one. A must read article!

# lKKuwcAiHxlmIpckVv 2018/12/28 3:12 http://dailypapa.com/__media__/js/netsoltrademark.

wow, awesome blog.Much thanks again. Fantastic.

# LxIouXRzVQGsgCC 2018/12/28 12:34 https://www.bolusblog.com/about-us/

Respect to post author, some superb entropy.

# IfFIKgYdMTAqfYzfF 2018/12/28 15:58 http://blucat.de/index.php?title=Benutzer:Reinaldo

Simply wish to say your article is as astonishing.

# sVcQWkMkJpIVwhip 2018/12/28 21:10 http://www.stockradar.com/__media__/js/netsoltrade

This particular blog is obviously educating additionally factual. I have found many helpful stuff out of this amazing blog. I ad love to go back again and again. Thanks a bunch!

# KXPqCfmYhmtdjlKZYo 2018/12/29 9:55 http://www.wuzhishan.hn.cn/home.php?mod=space&

This is a really good tip especially to those new to the blogosphere. Brief but very accurate info Many thanks for sharing this one. A must read article!

# uXoZzGTIMDrDFdjKs 2018/12/29 11:38 https://www.hamptonbaylightingcatalogue.net

Thanks a whole lot for sharing this with all of us you really know what you are speaking about! Bookmarked. Kindly also check out my web-site =). We could possess a link exchange contract amongst us!

# OmOvrhxokDUwavxtMbw 2019/01/02 22:22 http://pets-community.website/story.php?id=870

Very informative article.Really looking forward to read more. Much obliged.

# xzxlVvjqsHrOWEdD 2019/01/05 10:21 http://www.cornmuffin.net/__media__/js/netsoltrade

Thanks for the blog article.Much thanks again. Much obliged.

# XpVmRdWJsAo 2019/01/05 14:57 https://www.obencars.com/

Thanks again for the blog post.Thanks Again. Keep writing.

# UDqzoUVfwARbg 2019/01/06 1:00 http://www.feedbooks.com/user/4873815/profile

Really enjoyed this blog.Really looking forward to read more.

# RgxysREzPbgBV 2019/01/07 6:31 http://www.anthonylleras.com/

It as difficult to find well-informed people on this subject, but you sound like you know what you are talking about! Thanks

# JWWkhLKaaqsdioadZM 2019/01/07 8:19 https://status.online

Thanks for the blog post.Really looking forward to read more. Much obliged.

# jCEJqgdpkOXp 2019/01/07 10:08 http://disc-team-training-en-workshop.jigsy.com/

This blog is obviously awesome and besides amusing. I have chosen many helpful stuff out of this amazing blog. I ad love to return over and over again. Thanks a lot!

# VaZfTatZDQgQc 2019/01/08 1:18 https://www.youtube.com/watch?v=yBvJU16l454

pretty helpful stuff, overall I believe this is really worth a bookmark, thanks

# vNmtOIeJKetvgAeHAg 2019/01/09 20:02 http://am-lean.ru/bitrix/rk.php?goto=http://bookma

this content Someone left me a comment on my blogger. I have clicked to publish the comment. Now I wish to delete this comment. How do I do that?..

# HqRXiXEXets 2019/01/09 22:27 http://bodrumayna.com/

Terrific work! This is the type of information that should be shared around the web. Shame on Google for not positioning this post higher! Come on over and visit my web site. Thanks =)

# qOwSWgEPoug 2019/01/10 2:13 https://www.youtube.com/watch?v=SfsEJXOLmcs

It as difficult to find experienced people for this subject, but you seem like you know what you are talking about! Thanks

# jIrkpUjRiuVMf 2019/01/11 0:50 http://seniorsreversemortej3.tubablogs.com/i-monit

Its hard to find good help I am constantnly proclaiming that its hard to find good help, but here is

# jfLxVujFSyFKF 2019/01/11 4:35 http://joan5689el.firesci.com/the-investor-is-the-

This is one awesome article post.Thanks Again. Keep writing.

# mLqFmWbqxLYHgoPnSta 2019/01/11 23:49 http://globalretailmall.com/__media__/js/netsoltra

Thanks so much for the blog article.Much thanks again. Want more.

# efTXzsUEbY 2019/01/12 3:37 https://challenges.openideo.com/profiles/697a150cc

Very neat article.Thanks Again. Really Great.

# YxNIeiIgjeMa 2019/01/12 5:30 https://www.youmustgethealthy.com/privacy-policy

Some really great information, Glad I noticed this.

# lhjsJEYHkpdP 2019/01/15 4:44 https://cyber-hub.net/

This is one awesome post.Much thanks again. Much obliged.

# HjJJNbcygbOxANKj 2019/01/15 8:47 https://wiki.cizaro.com/index.php?title=User:YXABe

Some really fantastic articles on this web site , regards for contribution.

# GWdMkxuDIb 2019/01/15 23:27 http://dmcc.pro/

Spot on with this write-up, I really feel this website needs a lot more attention. I all probably be back again to see more, thanks for the information!

# OhsrKSekcNlbtOACa 2019/01/16 19:26 http://massaggiodiluce.org/__media__/js/netsoltrad

I wish to read even more things about it!

# kBgEgzumbwMDWNFvWh 2019/01/18 21:36 http://odbo.biz/users/MatPrarffup433

ppi claims ireland I work for a small business and they don at have a website. What is the easiest, cheapest way to start a professional looking website?.

# UjCwAQYLbYQSVgzav 2019/01/23 7:28 http://forum.onlinefootballmanager.fr/member.php?1

You have brought up a very excellent points , thanks for the post. Wit is educated insolence. by Aristotle.

# DKxiPTSkbe 2019/01/23 9:34 http://forum.onlinefootballmanager.fr/member.php?1

Well I truly liked studying it. This information procured by you is very practical for correct planning.

# ITAoUnvVGRFjWadnX 2019/01/23 21:40 http://travianas.lt/user/vasmimica914/

It as great that you are getting ideas from this piece of writing as well as from our discussion made at this time.

# BlCcNJCeVFGX 2019/01/24 4:17 http://forum.onlinefootballmanager.fr/member.php?1

Is it just me or does it look like like some

# hxvBzOfhjgeHd 2019/01/25 15:43 http://kikusui-korea.co.kr/Product/348813

It as exhausting to seek out knowledgeable individuals on this matter, however you sound like you know what you are speaking about! Thanks

# qWrQGKHMOut 2019/01/26 7:01 http://ismael8299rk.envision-web.com/this-is-a-rea

Thanks, Your post Comfortably, the article

# fezYbLUXcpt 2019/01/26 11:24 https://allihoopa.com/kaleyreid

Pretty! This was an incredibly wonderful post. Thanks for supplying these details.

# TIXDWDAoGyKjZkCz 2019/01/26 13:37 http://easbusinessaholic.website/story.php?id=6980

Thanks-a-mundo for the blog.Really looking forward to read more. Want more.

# GJwVbAnhrEcSe 2019/01/26 19:02 https://www.womenfit.org/category/women-health-tip

to ask. Does operating a well-established blog like yours take

# kHEgNgtDnhuvxLcHsFY 2019/01/28 18:25 https://www.youtube.com/watch?v=9JxtZNFTz5Y

There may be noticeably a bundle to know about this. I assume you made sure good factors in features also.

# DOLOYjOCNYfhSNPfuP 2019/01/29 0:54 http://www.crecso.com/category/technology/

share. I know this is off subject but I just wanted to ask.

# pnkOqQUXkqDNvimJ 2019/01/29 3:12 https://www.tipsinfluencer.com.ng/

Wow, awesome blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your web site is great, let alone the content!

# nbMqoggyJto 2019/01/29 5:25 https://www.hostingcom.cl/hosting

Some truly prime articles on this internet site , saved to fav.

# NLiHXCDhUJKtcWWx 2019/01/30 5:19 http://bgtopsport.com/user/arerapexign907/

This is a topic that is close to my heart Cheers! Where are your contact details though?

# qylIEppFPseDCpJLvCH 2019/01/31 0:27 http://gestalt.dp.ua/user/Lededeexefe165/

Inspiring quest there. What occurred after? Thanks!

# GjgYZrzPRioRW 2019/01/31 2:46 http://computerventures.com/__media__/js/netsoltra

Thanks for such a good blog. It was what I looked for.

# oEgPIQhvCxxA 2019/01/31 7:18 http://forum.onlinefootballmanager.fr/member.php?1

Tremendous details thanks a lot for publishing. The truth is in all of the content on this blog you will find something to understand.

# sIYauHPOYRpnSMVH 2019/01/31 18:21 http://silverpage98.xtgem.com/__xt_blog/__xtblog_e

me. Anyhow, I am definitely glad I found it and I all be bookmarking and checking back often!

# hVLKzGpgOxdX 2019/02/01 2:39 http://forum.onlinefootballmanager.fr/member.php?1

louis vuitton wallets ??????30????????????????5??????????????? | ????????

# sNkkDGmdlQVunzSh 2019/02/02 20:35 http://court.uv.gov.mn/user/BoalaEraw185/

Sweet blog! I found it while surfing around on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I ave been trying for a while but I never seem to get there! Cheers

# ASIWgwfptYsMjDW 2019/02/03 4:53 https://visual.ly/users/dylanpeppin/portfolio

There as definately a great deal to know about this subject. I like all the points you have made.

# ZFxYXyZsdTbDSawT 2019/02/03 13:36 http://hanamenc.co.kr/xe/?document_srl=5261394

Some truly superb information, Glad I observed this.

# jLlLdloWOpLTMNg 2019/02/03 18:05 http://outlookfinancial.org/__media__/js/netsoltra

What as up, just wanted to tell you, I liked this blog post. It was funny. Keep on posting!

# jyaTNExXagaVIYQ 2019/02/03 20:20 http://forum.onlinefootballmanager.fr/member.php?1

My brother suggested I might like this blog. He was totally right. This post truly made my day. You can not imagine simply how much time I had spent for this info! Thanks!

# dREHHrqHcokaFQV 2019/02/05 15:38 https://www.ruletheark.com/how-to-join/

Personally, I have found that to remain probably the most fascinating topics when it draws a parallel to.

# VhUqNizWiVfrx 2019/02/05 17:56 https://www.highskilledimmigration.com/

web site which offers such data in quality?

# MNDlUVhfpgazyeMBM 2019/02/05 23:02 http://www.samplecloset.net/__media__/js/netsoltra

Some truly fantastic information, Gladiolus I detected this.

# tvDvpzWDdVVTuzrjxiW 2019/02/06 23:06 http://www.cheaphalloween.com/__media__/js/netsolt

Respect to op , some wonderful information.

# ZhvJtxfGNbZedjqWtTw 2019/02/07 2:32 http://manxrule3.macvoip.com/post/saatnya-kamu-gab

I really liked your post.Really looking forward to read more.

# ITPkOEcWMoo 2019/02/07 4:54 http://high-mountains-tourism.com/2019/02/05/banda

This blog was how do you say it? Relevant!! Finally I ave found something that helped me. Thanks a lot!

# hnduGtVgEJCRo 2019/02/07 7:15 https://www.abrahaminetianbor.com/

you put to make such a magnificent informative website.

# OvSFqrrjvLuP 2019/02/09 2:22 https://bomberindex09.phpground.net/2019/02/08/the

I truly appreciate this post. I ave been looking everywhere for this! Thank goodness I found it on Bing. You ave made my day! Thx again!

# IkrNAZxNiD 2019/02/09 2:28 http://bookmarksync.xyz/story.php?title=potenciale

This is a topic that is close to my heart Take care! Where are your contact details though?

# noCLAKPNrGdwjAkqsET 2019/02/12 2:39 https://www.openheavensdaily.com

I see something truly special in this site.

# LFtIzvAweZzX 2019/02/12 20:19 https://www.youtube.com/watch?v=bfMg1dbshx0

Thanks a lot for the blog. Keep writing.

# qmcIeppvkdukIhYXVO 2019/02/12 22:38 pobieramy.top/pobierz/9Ep9Uiw9oWc

Well I definitely liked reading it. This article offered by you is very effective for accurate planning.

# FKhohPSiOrfOP 2019/02/13 0:52 https://www.youtube.com/watch?v=9Ep9Uiw9oWc

Utterly pent content material, thanks for information.

# cbltihPtMbVjP 2019/02/13 12:02 http://factrocket81.thesupersuper.com/post/tembak-

It as hard to come by educated people for this subject, however, you sound like you know what you are talking about! Thanks

# TyVlQyMIrRKz 2019/02/14 2:55 http://freedomsroad.org/community/members/pastaclo

Wow, fantastic weblog format! How lengthy have you ever been blogging for? you made running a blog glance easy. The total glance of your web site is wonderful, let alone the content!

# gCvWxvOcZWf 2019/02/15 4:53 http://theyeslaptop.site/story.php?id=4848

taureau mai My blog post tirage tarot gratuit

# MwPWtvVsWG 2019/02/15 11:37 http://www.trestoremolise.it/index.php?option=com_

This awesome blog is really awesome as well as diverting. I have picked helluva helpful advices out of this source. I ad love to come back again and again. Thanks a lot!

# tKvtAaqDDLp 2019/02/15 23:14 http://all4webs.com/pricemetal53/puczuiqebx316.htm

This unique blog is no doubt entertaining and besides diverting. I have found many useful advices out of this amazing blog. I ad love to go back over and over again. Cheers!

# QxqLrXEWQUtJEDcpWVE 2019/02/18 22:08 http://thesocialbuster.com/story.php?title=worcest

Would you be interested by exchanging hyperlinks?

# LyQUAETFCUBipIIgTcp 2019/02/19 0:29 https://www.highskilledimmigration.com/

There is perceptibly a bunch to identify about this. I suppose you made some good points in features also.

# ifjaQcJpLeM 2019/02/19 3:18 https://www.facebook.com/เส&am

I truly appreciate this blog post.Thanks Again. Keep writing.

# qbUEoymystmq 2019/02/20 18:22 https://www.instagram.com/apples.official/

It as a very easy on the eyes which makes it much more enjoyable for me

# opimuRaCYlgjM 2019/02/20 20:54 https://giftastek.com/product-category/computer-la

You obviously know your stuff. Wish I could think of something clever to write here. Thanks for sharing.

タイトル  
名前  
Url
コメント