2014-03-25 36 views
0
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 

现在,我有编码在当前目录中保存文本文件。但是,我想为用户提供浏览按钮,以便他们可以选择保存此文本文件的位置。我如何继续?Visual Basic窗体。如何让用户保存他们想要的文本文件

我正在尝试通过我自己,我在使用保存文件对话框时遇到了麻烦。如果您可以教我如何使用保存文件对话框或反正写保存浏览按钮,我将不胜感激!

+0

是您遇到了什么麻烦。请明确点。 –

+0

我在工具箱上发现了一个保存文件对话框工具,并试图将它与按钮组合起来,但它不起作用。我不知道如何基本开始。 – user3396709

+0

“它没有工作” - 具体。 –

回答

1

SaveFileDialog对象的文档包含example

+0

从示例中,这是什么意思'代码写入流到这里。'?我应该写IO.File.WriteAllLines(Stream,Result1.Lines)吗? – user3396709

+0

而不是使用'myStream'的代码,使用'IO.File.WriteAllLines(saveFileDialog1.FileName,Result1.Lines)'。 – prprcupofcoffee

+0

我试过了,但它说它正在被另一个对我没有意义的过程使用。无论如何我都没有使用这个文本文件。它只会在我指出的位置上生成一个空白的txt文件。 如果saveFileDialog1.ShowDialog()= DialogResult.OK然后 myStream = saveFileDialog1.OpenFile() 如果(myStream IsNot运算没有什么)然后 IO.File.WriteAllLines(saveFileDialog1.FileName,Result1.Lines) – user3396709

0

这里是一个关于如何使用Visual Studio中的工具箱实现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 
相关问题