VB.NET中带有文本框的FolderBrowser [英] FolderBrowser with textbox in VB.NET
问题描述
我有一个textBox,它充满了从数据库获取的路径(但这无关紧要).所以我想有一个FolderBrowserDialog按钮,在其中打开->浏览文件夹并选择一个路径(即通过选择某个文件夹),然后确定/保存该路径并将其在文本框中更新.
I have a textBox which gets filled with a path, acquired from a database (but that's irrelevant). So I want to have a FolderBrowserDialog button where I open -> navigate through the folders and select a path (i.e. by selecting a certain folder) and then OK/Save-ing this path and it to be updated in the textBox.
因此,在整个情况下-我不知道如何使用OpenFolderBrowserDialog,因为当我拖动它时-它只会出现在页面底部,但是我想将其作为按钮放置在我的WinForm. 还有-所选路径如何保存到(即字符串)变量中,以便可以将其设置为文本框的值?某种方法?
So in the whole case - I don't know how to use the OpenFolderBrowserDialog, because when I drag it - it only goes in the bottom of the page, but I want to place it as a button on a certain place in my WinForm. And also - how is the selected path saved into a (i.e. string) variable so I can set it as the value of the textbox? A certain method?
推荐答案
尝试如下所示将对您有所帮助.
Try like below it will help you..
将Text box
,Button
和FolderBrowserDialog
放置在Form
中,如下所示...
Place a Text box
, Button
and FolderBrowserDialog
in your Form
like below...
然后在您的代码上Double click the button
和create Button click Event
如下.
Then Double click the button
and create Button click Event
on your code like below..
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then
TextBox1.Text = FolderBrowserDialog1.SelectedPath
End If
End Sub
然后运行它.现在,您可以通过单击浏览"按钮来打开文件夹浏览器"对话框.
Then run it.. Now you can open the Folder Browser dialog by clicking the Browse Button..
选择文件夹路径后,路径将分配给文本框
After selecting the folder Path the path will assigned to Text Box
您也可以参考此文章以获取完整参考: FolderBrowserDialog
You can also refer this Article for full reference : FolderBrowserDialog
这篇关于VB.NET中带有文本框的FolderBrowser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!