using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Windows.Forms.Design;namespace 最简单文件夹对话框
{
public class FolderDialog : FolderNameEditor
{
FolderNameEditor.FolderBrowser fDialog = new System.Windows.Forms.Design.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();
}
} /// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null) 
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
// 
// mainMenu1
// 
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  this.menuItem1});
// 
// menuItem1
// 
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  this.menuItem2,
  this.menuItem3,
  this.menuItem4});
this.menuItem1.Text = "文件";
// 
// menuItem2
// 
this.menuItem2.Index = 0;
this.menuItem2.Text = "忝加目录";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
// 
// menuItem3
// 
this.menuItem3.Index = 1;
this.menuItem3.Text = "-";
// 
// menuItem4
// 
this.menuItem4.Index = 2;
this.menuItem4.Text = "请指点目录打开目录对话框";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
// 
// textBox1
// 
this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
| System.Windows.Forms.AnchorStyles.Right);
this.textBox1.Location = new System.Drawing.Point(40, 8);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(240, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
// 
// label1
// 
this.label1.Location = new System.Drawing.Point(8, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 23);
this.label1.TabIndex = 1;
this.label1.Text = "路径";
// 
// Form1
// 
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(288, 229);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
  this.label1,
  this.textBox1});
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main() 
{
Application.Run(new Form1());
} private void menuItem2_Click(object sender, System.EventArgs e)
{
FolderDialog openFolder = new FolderDialog();
openFolder.DisplayDialog();
}
希望对你有帮助!记得在项目忝加引用——System.Design.dll
要不然好像不能通过编译!

解决方案 »

  1.   

    这个问题我问过许多次了,一直没有人真正解答或给出一个source
      

  2.   

    有一点可以肯定,需要调用api的,好像是shell32.dll
      

  3.   

    比较简单,你可以用Treeview+ImageList,你可以用篇历,也可以用实时的执行来获取其目录,你可以把这个例子下来看看
    http://www.hnwh.com/download/dotnet/control/treeview.zip
      

  4.   

    http://www.hnwh.com/download/dotnet/control/tv1.zip
    http://www.hnwh.com/download/dotnet/control/tv2.zip我的电脑这个节点可以自己加的,其它的比如说我的文档,网上邻居之灰的也可以自己另外加上去
      

  5.   

    其实可以看看最新的Delphi 6里面的新加的一个控件,直接实现这个功能!