简体   繁体   English

在显示对话框上保存文件路径

[英]Save file path on show dialog

I want to save path on text box after Directory 1: whenever I try to close the application and open again the path is not there.I want it to show every time I open the application. 我想在目录1之后的文本框中保存路径:每当我尝试关闭应用程序并再次打开时,路径都不存在。我希望每次打开应用程序时都显示该路径。

在此处输入图片说明

Private Sub btnRootBrowse1_Click(sender As System.Object, e As System.EventArgs) Handles btnBrowse1.Click
        RootFolderBrowserDialog.ShowDialog()
        txtPath1.Text = RootFolderBrowserDialog.SelectedPath
    End Sub

You need save your data (in this case txtPath1.Text) to Hard-Drive (File or DataBase) and reload it in the next execution. 您需要将数据(在这种情况下为txtPath1.Text)保存到硬盘驱动器(文件或数据库),并在下一次执行时重新加载。

It can be easy when you use Application-Setting : 使用Application-Setting可以很容易:

  1. In the Solution Explorer, Double-Click "My Project" 在解决方案资源管理器中,双击“我的项目”
  2. in left pane click "Setting" 在左窗格中,单击“设置”
  3. in the table, Fill in the fields as needed, example for you case: Name: DirectoryLocation Type: String Scope: User Value: Empty. 在表中,根据需要填写字段,例如您的情况:名称:DirectoryLocation类型:String范围:用户值:空。
  4. Sample Code Using: 示例代码使用:

     Public Sub New() InitializeComponent() 'load from the hard-disk txtPath1.Text = My.Settings.DirectoryLocation End Sub Private Sub btnRootBrowse1_Click(sender As System.Object, e As System.EventArgs) Handles btnBrowse1.Click RootFolderBrowserDialog.ShowDialog() txtPath1.Text = RootFolderBrowserDialog.SelectedPath 'save to hard-disk My.Settings.DirectoryLocation = txtPath1.Text My.Settings.Save() End Sub 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM