在你的工程中添加对
“Microsoft.VisualBasic.Compatibility.VB6.DirListBox”
的引用就可以使用VB6传统的目录对话框了
“Microsoft.VisualBasic.Compatibility.VB6.DirListBox”
的引用就可以使用VB6传统的目录对话框了
解决方案 »
- 请教正则表达式,匹配bdhd://到.rmvb
- 求一个正则表达式替换字符串写法
- c#用Linq语句操作DataGridView
- 在C# winform中怎么创建DataGridView??/???
- 请问xp下能开发asp.net2.0吗?
- 异常处理系统设计
- 在.net中,longraw类型的数据如何读出?谢谢!
- 如何捕获datagrid中的模板列事件?
- 请问可以用C#获取当前用户的宽带账号么?
- 请问各位大虾,在C#程序中怎么在一个窗体中引用另外一个窗体中的变量
- 300分求解关于CDO的问题
- 高手、微软专家:请问有什么办法提高控件的绘制速度,在XP中绘制透明控件十分缓慢(P4 128MB)有无办法解决
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);
}
能否给个调用这个API函数SHBRowseForFolder的例子???
不会真要我调用VB的这个对话框才能解决吧!
谢谢了。
谢谢了。:)
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))。
我想知道调API的原码有吗???
谢谢了。
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
}
兄台怎么一堆错误呀!!!!!!!!!!!!
我以引用了。System.Runtime.InteropServices;
可是说什么sell32名字空间没定义?????????????
还有呀!
看来这个目录对话框只能自已写一个了:(
调用现承的好像不大可能了:(
谢谢这个点击该铵钮的原码?谢谢了。我初学真型不懂是什么原因?
就只能播放一首歌!就停止不动了。:(
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);
}
}