Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
Dim CurrentDir As String = Environment.CurrentDirectory
Dim OutputFile2 As String = IO.Path.Combine(CurrentDir, "input.txt")
IO.File.WriteAllLines(OutputFile2, Result1.Lines)
End Sub
现在,我有编码将文本文件保存在当前目录中。但是,我希望为用户提供一个浏览按钮,以便他们可以选择保存此文本文件的位置。我该如何处理?
我是靠自己尝试的,而且我在使用保存文件对话框时遇到了麻烦。如果您可以教我如何使用保存文件对话框或者无论如何编写保存浏览按钮,我将非常感激!
答案 0 :(得分:1)
SaveFileDialog对象的文档包含example。
答案 1 :(得分:0)
这是一个如何在Visual Studio中使用Toolbox实现SaveFileDialog的教程,就像你提到的那样。代码示例在C#中,但可以很容易地转换为VB。
链接:www.dotnetperls.com/savefiledialog
Private Sub button1_Click(sender As Object, e As EventArgs)
' When user clicks button, show the dialog.
saveFileDialog1.ShowDialog()
End Sub
Private Sub saveFileDialog1_FileOk(sender As Object, e As CancelEventArgs)
' Get file name.
Dim name As String = saveFileDialog1.FileName
' Write to the file name selected.
' ... You can write the text from a TextBox instead of a string literal.
File.WriteAllText(name, "test")
End Sub