在你的工程中添加对
“Microsoft.VisualBasic.Compatibility.VB6.DirListBox”
的引用就可以使用VB6传统的目录对话框了

解决方案 »

  1.   

    .....
    private Microsoft.VisualBasic.Compatibility.VB6.DirListBox dirListBox;
    private Microsoft.VisualBasic.Compatibility.VB6.DriveListBox driveListBox;
    .....//使dirListBox和driveListBox关联的函数
    private void driveListBox_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    //System.Exception error;
    try
    {
    dirListBox.Path=driveListBox.get_Items( driveListBox.SelectedIndex);
    }
    catch(System.Exception error)
    {
    MessageBox.Show(this,error.Message,"Error!",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Information);
    }
      

  2.   

    我不会用VB呀! 没学过呀!
    能否给个调用这个API函数SHBRowseForFolder的例子???
    不会真要我调用VB的这个对话框才能解决吧!
    谢谢了。
      

  3.   

    你留个EMAIL,我把我的程序发给你看,好吗?
      

  4.   

    [email protected]
    谢谢了。:)
      

  5.   

    感谢您使用微软产品。目前,.NET Framework没有直接提供打开目录(文件夹)对话框。不过,您可以按照如下的步骤,在VC#中实现自定义目录(文件夹)对话框(Folder Dialog),然后可以在VC#和VB.NET中调用:
    1,首先建立一个FolderDialog的类文件,并将其编译成为dll文件,以便其他应用程序调用:
    具体过程如下:
    (1)新建一个Window Application应用程序(注:在调试通过后,可改为Class Library输出),右击ToolBox,选择Customize ToolBox……,在弹出的Customize ToolBox对话框中,选择“.Net Framework Component”,最后在列表中选中DriveListBox, DirListBox 和 FileListBox等复选框;
    (2)添加DriveListBox, DirListBox 和 FileListBox到Form窗体上,并编写如下代码(只列出一些主要的代码,供参考):
    using ……;
    namespace CustomerFolderDialog
    {
    public class FolderDialog : System.Windows.Forms.Form
    {
    public string Path
    {
    get { return dirListBox1.Path; }
    }
    private string tempDrive;
    ……
    public FolderDialog()
    {
    InitializeComponent();
    tempDrive = this.driveListBox1.Drive;
    }
    ……
    private void driveListBox1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    try
    {
    this.dirListBox1.Path = this.driveListBox1.Drive;
    tempDrive = this.driveListBox1.Drive;
    }
    catch(Exception ex)
    {
    MessageBox.Show(ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
    driveListBox1.Drive = tempDrive;
    }
    } private void Form1_Load(object sender, System.EventArgs e)
    {
    this.label1.Text = dirListBox1.Path;
    } private void dirListBox1_Change(object sender, System.EventArgs e)
    {
    try
    {
    this.fileListBox1.Path = this.dirListBox1.Path;
    this.label1.Text = dirListBox1.Path;
    }
    catch(Exception ex)
    {
    MessageBox.Show(ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
    }
    }
    }
    }
    (3),在调试通过后,在Form窗体上添加两个Button,并分别设置DialogResult属性为:OK或Cancel,分别设置其Text属性为OK或Cancel。同时,在应用程序的属性对话框 (Project/Properties) 中将其Output Type改为Class Library,编译输出dll文件。2,另外新建一个C#的应用程序,添加对上述dll文件的引用(Add Reference)。
    下面提供一段示例程序,完成整个调用过程:
    ……
    using CustomerFolderDialog;
    ……
    private void button1_Click(object sender, System.EventArgs e)
    {
    FolderDialog folderDialog = new FolderDialog();
    if(folderDialog.ShowDialog() == DialogResult.OK)
    {
    textBox1.Text = folderDialog.Path;
    }
    }
    希望这些对您有帮助,如果有问题,请继续讨论! — 微软全球技术中心 VB支持中心本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
    为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
      

  6.   

    谢谢楼上兄弟对我帮助很大呀1
    我想知道调API的原码有吗???
    谢谢了。
      

  7.   

    string    folderToReturn = null;
    try {
    Shell32.Shell shell = new Shell32.Shell ();
    Shell32.Folder folder            = shell.BrowseForFolder(this.Handle.ToInt32(), "Select a folder", 8, "");
    Shell32.FolderItems folderItems = folder.Items();
    Shell32.FolderItem    folderItem  = folderItems.Item(0);
    String    fullPath                = folderItem.Path;
    // Now parse out the unecessary final part
    fullPath    = fullPath.Substring(0, fullPath.LastIndexOf(@"\"));
    folderToReturn = fullPath;
    }catch {
    // An error occured. Just igonre it, null will be returned - we called a silly DLL anyway
    }
      

  8.   

    TO:confucian(黄山顶上一根葱) 
    兄台怎么一堆错误呀!!!!!!!!!!!!
    我以引用了。System.Runtime.InteropServices;
    可是说什么sell32名字空间没定义?????????????
    还有呀!
    看来这个目录对话框只能自已写一个了:(
    调用现承的好像不大可能了:(
      

  9.   

    不好意思能否帮我看一下为什么不能连续播放一个目录下的所有MP3文件呢???
    谢谢这个点击该铵钮的原码?谢谢了。我初学真型不懂是什么原因?
    就只能播放一首歌!就停止不动了。:(
    private void menuItem3_Click(object sender, System.EventArgs e)
        {
     try 
          {

    string [] tempName = Directory.GetFiles("E:\\PLAY。EXE\\share");
     
     foreach(string FileName in tempName)
     {
     this.axMediaPlayer1.FileName =FileName;

               }
     
      }
      
    catch 
       {
     MessageBox.Show("not open file" ,"Tip" , MessageBoxButtons.OK, MessageBoxIcon.Error);
       }
    }