我有一个文本框(textbox1),当加载 WPF 窗口时,它使用 UserProfile 变量在 textbox1.text 中显示当前用户目录
Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
Dim defaultpath As String = Environment.CurrentDirectory
Environment.CurrentDirectory = Environment.GetEnvironmentVariable("UserProfile")
TextBox1.Text = defaultpath
End Sub
我还有一个按钮,单击该按钮时,使用 FolderBrowserDialog 浏览文件夹,然后在 textbox1.text 中显示新文件夹路径。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim fldDialog As New FolderBrowserDialog()
fldDialog.RootFolder = Environment.SpecialFolder.Desktop
fldDialog.ShowDialog()
Dim filepathstore As String = fldDialog.SelectedPath
TextBox1.Text = filepathstore
End Sub
该值现在显示使用 FolderBrowserDialog 选择的路径。
我将如何存储这个新值,当 WPF 窗口关闭/重新打开时,显示这个新值而不是默认值。(替换不删除默认值)
文件夹路径的这个新值可以根据需要多次更改。但是,当单击重置按钮时,WPF 窗口将恢复为默认值。