如何在Environment.SpecialFolder中使用FolderBrowserDialog? [英] How do I use a FolderBrowserDialog with Environment.SpecialFolder?
问题描述
我目前正在编写一个轻巧灵活的程序来查看和编辑图片.一切进展顺利,但我遇到了障碍. FolderBrowserDialog控件的RootFolder属性是Environment.SpecialFolder类型的,它是一个枚举.由于这种性质,我无法将其值设置为字符串.如何使用FolderBrowserDialog的SelectedPath属性设置FolderBrowserDialog的RootPath属性?
(注意:FolderBrowserDialog用于选择从中打开图像的默认文件夹)
I currently am writing a lightweight and flexible program to view and possibly edit pictures. Everything is going smoothly, but I''ve run into a roadblock. The RootFolder property of a FolderBrowserDialog control is of the Environment.SpecialFolder type, which is an enum. Due to this nature, I can''t set its value as a string. How can I use the SelectedPath property of the FolderBrowserDialog to set the RootPath property for a FolderBrowserDialog?
(Note: The FolderBrowserDialog is for selecting the default folder for opening images from)
推荐答案
尝试使用Environment.SpecialFolder.MyComputer
,设置SelectedPath
,然后调用.我做了以下工作,效果很好:
Try usingEnvironment.SpecialFolder.MyComputer
, set theSelectedPath
, and then callShowDialog()
. I did the following and it worked fine:
FolderBrowserDialog dlg = new FolderBrowserDialog();
dlg.RootFolder = Environment.SpecialFolder.MyComputer;
dlg.SelectedPath = @"d:\dev";
dlg.ShowDialog();
我认为您需要看一下:Environment.GetFolderPath(Environment.SpecialFolder).
如果将此调用的结果提供给FolderBrowserDialog,则应该没问题.
有关GetFolderPath的更多详细信息: http://msdn.microsoft.com/en-us/library/14tx8hby.aspx [ ^ ]
干杯,AT
Hi,
I think you need to take a look at: Environment.GetFolderPath(Environment.SpecialFolder).
If you feed the result of this call to the FolderBrowserDialog you should be OK.
for more detail info on the GetFolderPath: http://msdn.microsoft.com/en-us/library/14tx8hby.aspx[^]
Cheers, AT
这篇关于如何在Environment.SpecialFolder中使用FolderBrowserDialog?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!