如何制作OpenFileLocation按钮 [英] How to make OpenFileLocation button

查看:160
本文介绍了如何制作OpenFileLocation按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想知道如何构建OpenFileLocation按钮.
我的意思是,选择浏览"后,ofd会显示出来.我选择.exe或其他内容,然后将其打印到textbox1.text

Hey

I want to know how to build OpenFileLocation button.
I mean , after I select browse , ofd shows up. I select the .exe or whatever , then it prints to textbox1.text

OpenFileDialog ofd = new OpenFileDialog();
            
            
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.textBox1.Text = ofd.FileName;
                
            }


我创建了这个


and I created this

Process.Start(textbox1.Text)


但是,我想创建一个按钮来打开文件夹,该文件夹找到我从浏览按钮中选择的exe.
像,打开文件位置按钮
我试过了


but , I want to create a button to open the folder which locates the exe i selected from the browse button.
Like , Open file location button
I tried this

if (ofd.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = OpenFileDialog;
            }


但是,它没有用.


But , it didnt worked.

推荐答案

使用FolderBrowserDialog类


Use the FolderBrowserDialog class


if (ofd.ShowDialog() == DialogResult.OK)
{
   FolderBrowserDialog dialog = new FolderBrowserDialog();
   dialog.SelectedPath = Path.GetDirectoryName(ofd.FileName);
   dialog.ShowDialog();
   textBox1.Text = dialog.SelectedPath;
}


这篇关于如何制作OpenFileLocation按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆