收录日期:2020/01/29 16:03:33 时间:2016/05/18 23:55:23 标签:C#
用哪些控件可以显示硬盘里的东西~
比如我想显示c盘里的文件,该怎么办?
谢谢~
use classes in System.IO, or see

My Explorer In C#
http://www.thecodeproject.com/csharp/My_Explorer.asp
look this:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;

namespace FolderBrowser
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class FolderDialog : System.Windows.Forms.Form
{
        private System.Windows.Forms.ImageList fileIconList;
        private System.Windows.Forms.TreeView FolderTree;
        private System.ComponentModel.IContainer components;

public FolderDialog()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null) 
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
            this.components = new System.ComponentModel.Container();
            System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FolderDialog));
            this.fileIconList = new System.Windows.Forms.ImageList(this.components);
            this.FolderTree = new System.Windows.Forms.TreeView();
            this.SuspendLayout();
            // 
            // fileIconList
            // 
            this.fileIconList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
            this.fileIconList.ImageSize = new System.Drawing.Size(16, 16);
            this.fileIconList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("fileIconList.ImageStream")));
            this.fileIconList.TransparentColor = System.Drawing.Color.Transparent;
            // 
            // FolderTree
            // 
            this.FolderTree.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
                | System.Windows.Forms.AnchorStyles.Left) 
                | System.Windows.Forms.AnchorStyles.Right);
            this.FolderTree.ImageList = this.fileIconList;
            this.FolderTree.Name = "FolderTree";
            this.FolderTree.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
                                                                                   new System.Windows.Forms.TreeNode("我的电脑", 0, 0)});
            this.FolderTree.Size = new System.Drawing.Size(470, 350);
            this.FolderTree.TabIndex = 0;
            this.FolderTree.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.FolderTree_AfterSelect);
            // 
            // FolderDialog
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(472, 353);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.FolderTree});
            this.Name = "FolderDialog";
            this.Text = "浏览我的电脑";
            this.ResumeLayout(false);

        }
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() 
{
Application.Run(new FolderDialog());
}

        private void FolderTree_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
        {
            if(e.Node.Text.ToString()!="我的电脑")
                EnumDirectories(e.Node);
            else
                EnumDrives(e.Node);
        }

        private void EnumDrives(TreeNode ParentNode)
        {
            if(ParentNode.Nodes.Count==0)
            {    
                foreach(string drive in Directory.GetLogicalDrives())
                {
                    FolderTree.SelectedNode=ParentNode;
                    TreeNode TempNode=new TreeNode();
                    TempNode.Text=drive.Substring(0,drive.Length-1);
                    TempNode.Tag=drive;
                    TempNode.ImageIndex=1;
                    TempNode.SelectedImageIndex=1; 
                    FolderTree.SelectedNode.Nodes.Add(TempNode);
                    FolderTree.SelectedNode.Nodes[FolderTree.SelectedNode.Nodes.Count-1].EnsureVisible();
                }
            }
        }

        private void EnumDirectories(TreeNode ParentNode)
        {
            FolderTree.SelectedNode=ParentNode;
            string DirectoryPath=ParentNode.Tag.ToString();
            if(ParentNode.Nodes.Count==0)
            {
                if(DirectoryPath.Substring(DirectoryPath.Length-1)!=@"\")
                    DirectoryPath+=@"\";
                try
                {
                    foreach(string directory in Directory.GetDirectories(DirectoryPath))
                    {
                        TreeNode TempNode=new TreeNode();
                        TempNode.Text=directory.Substring(directory.LastIndexOf(@"\")+1);
                        TempNode.Tag=directory;
                        TempNode.ImageIndex=3;
                        TempNode.SelectedImageIndex=2;
                        FolderTree.SelectedNode.Nodes.Add(TempNode);
                        FolderTree.SelectedNode.Nodes[FolderTree.SelectedNode.Nodes.Count-1].EnsureVisible();
                    }
                }
                catch(Exception)
                {
                }
            }
        }
}
}
谢谢了~

小面包车里你塞64个人,你以为你是超级塞压人啊 麻烦帮我解决下,为什么在用Smarty3.15时{% $content %}不能替换? xp连接windows2003远程桌面问题 jsoncpp,release出错 多线程 求VC++操作XML文件的Demo VB 实错误 对象\'Navigate\'的方法\'IWebBrowser2\'失败 asp一个增加产品的页面提示无效字符怎么回事? 求解本人安装jdk不能卸载?? 十六进制转换问题,非常奇怪,数据都可以转换,就是不能转换00这样的字符串,希望大家帮帮忙 MFC中如何用,列表框(clistbox)和编辑框,按矩阵的样子输出一个二维数组!! 【求助】华为2403交换机端口配置方法 【匆匆而过的豆蔻年华,少了一段轰轰烈烈的爱情,虽然有些惋惜,但我很知足。因为在每一个不同的心智阶段,都有一个人住在我心里。】 【求助】mfc多窗口下菜单项无法响应 asp新闻发布系统发布新闻时可设置为推荐新闻要怎么实现 bpel能不能使用drools JTree里不能加入hashtable函数 !!急 关于希尔排序 C#应用程式把jpg图片转化为tif(急) linux中断处理过程中何时开的中断? 在MVC开发中如何使用AutoMapper 我的程序在linux没有内存泄露,但是在AIX上内存一直往上涨,不释放,直到将我这个程序杀死 谁能解答一下这个问题 结构保存在栈,接口保存在堆,普通程序中的变量一般保存在栈?为啥这道题结果不是从栈中取值 求MVC历史 wince修改网卡IP地址 VS本地版本通过路径显示图片正确,网络发布版本的路径不能显示图片 tcp客户端连接两个tcp服务端后,如何区别发过来的数据属于哪个服务端? asp里页面中调用了百度地图api 为什么地图老显示在了左上角?? 有点复杂!