[英]Visual Studio file selector
I am new to .NET and the Visual Studio IDE. 我是.NET和Visual Studio IDE的新手。 How to I add to a form a component that lets the user browse the file system to select a certain file which will then allow me to programmatically use the selected path as a string variable? 如何向表单添加一个组件,让用户浏览文件系统以选择某个文件,然后允许我以编程方式将所选路径用作字符串变量?
this should do the trick: 这应该做的伎俩:
string path;
OpenFileDialog file = new OpenFileDialog();
if (file.ShowDialog() == DialogResult.OK)
{
path = file.FileName;
}
the string path should now contain the selected file path 字符串路径现在应包含选定的文件路径
OpenFileDialog should suit your needs. OpenFileDialog应该适合您的需求。 You'll probably need to put a button (or some other clickable type UI element) on the page that will pop the dialog up. 您可能需要在将弹出对话框的页面上放置一个按钮(或其他一些可点击类型的UI元素)。 Then once the user has selected a file and clicked "OK" you'll just check the response for which file was selected. 然后,一旦用户选择了一个文件并单击“确定”,您将只检查选择了哪个文件的响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.