当前位置:首页 > C#

C#选取文件夹的对话框

happyfhb13年前 (2013-10-28)C#1768
摘要: 首先要说明一下:添加引用:   System.Design  此文件在下面的位置   C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Design.dll…

 

首先要说明一下:

添加引用:   System.Design 

此文件在下面的位置 

 C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Design.dll

有些人说在添加引用的面板中并找不到这个引用.这是由于你的目标框架设置错误

在 解决方案管理器上  右键 "属性" --> 发布 --> 目标框架 修改为 .Net Framework 4.0  (没有那个client  )

这样你再在添加引用面板中就可以找到这个引用了.

 

添加这两个引用

using System.Windows.Forms;
using System.Windows.Forms.Design;


 

 

 

==================新建一个FolderDialog类 ==============

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
   public class FolderDialog : FolderNameEditor
    {
        FolderNameEditor.FolderBrowser fDialog = new FolderNameEditor.FolderBrowser();
        public FolderDialog()
        {
        }
        public DialogResult DisplayDialog()
        {
            return DisplayDialog("请选择一个文件夹");
        }
        public DialogResult DisplayDialog(string description)
        {
            fDialog.Description = description;
            return fDialog.ShowDialog();
        }
        public string Path
        {
            get { return fDialog.DirectoryPath; }
        }
        ~FolderDialog() { fDialog.Dispose(); }
    }

--------------调用--------------------

FolderDialog openFolder = new FolderDialog();
            if (openFolder.DisplayDialog() == DialogResult.OK)
            {
                textBox1.Text = openFolder.Path.ToString();
            }
            else
            {
                textBox1.Text = "你没有选择目录";
            }
            DirectoryInfo dirInfo = new DirectoryInfo(textBox1.Text);
            FileInfo[] files = dirInfo.GetFiles();
            foreach (FileInfo filename in files)
            {
                listBox1.Items.Add(filename);
            }

扫描二维码推送至手机访问。

版权声明:本文由海海日记-冯海滨博客发布,如需转载请注明出处。

本文链接:http://www.fenghaibin.com/?id=1125

“C#选取文件夹的对话框 ” 的相关文章

vb.net 随机函数 random 用法

VB.net 的写法dim rand as new random()i=rand.next(1,100)表示伪随机数生成器,一种能够产生满足某些随机性统计要求的数字序列的设备。命名空间:System程序集:mscorlib(在 mscorlib.dll 中)伪随机数是以相同的概率从一组有限的数字中选…

vb.net 多线程写法

注意 只能调用 不带参数的 sub 如果调用不同类的sub需要定义调用的sub是shared 是共享的 才可以的。相关语法Imports SystemImports System.Threading  '导入系统进程 Public Class Form1 &n…

c#中如何判断用户输入的字符全部为数字的方法-经典

             string num = textBox1.Text; //从文本框获取用户输入的值     …

C#延时方法片段

 label4.Text = "输入非数字字符";                //延时1秒  &…

C# 编写 Windows服务

. 新建一个项目2. 从一个可用的项目模板列表当中选择Windows服务3. 设计器会以设计模式打开4. 从工具箱的组件表当中拖动一个Timer对象到这个设计表面上 (注意: 工具箱中的timer 都是不对的,需要另行添加 详见方法 )&n…

C# windows服务程序中的Timer控件的添加方法

C# windows服务程序中的Timer控件的添加方法

开"工具箱"---右键---"选择项"---找到Timer控件,看好了,这个Timer控件的是system.Timer下的. 可不是System.Windows.Form.然后添加. …

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。