【发布时间】:2013-05-04 02:22:56
【问题描述】:
我正在寻找一个“另存为”对话框来处理我在 Visual Basic 中制作的应用程序的保存。
这是我正在使用的代码,我也不明白代码:
Private Sub MenuExportTo_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MenuExportTo.Click
Dim myStream As IO.Stream 'I don't understand this line
Dim saveFileDialog1 As New SaveFileDialog() 'I don't understand this line
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
'I understand this
saveFileDialog1.FilterIndex = 1 ' I understand this
saveFileDialog1.RestoreDirectory = True ' I understand this
If saveFileDialog1.ShowDialog() = DialogResult.OK Then
' I don't understand the rest
myStream = saveFileDialog1.OpenFile()
If (myStream IsNot Nothing) Then
' Code to write the stream goes here. (This was what the example
I referenced put here. the important code goes here, but the example was no help)
myStream.Close()
End If
End If
问题 1:我在这方面比较新,没有来源给我足够深入的解释来理解任何保存方法的真正含义。我需要一个可靠的解释,我迷路了。
问题 2:我可以将代码写入某个位置的文本文件,但返回的插入符号会丢失,它会在一行中保存到文本文件中,使用以下方法:
My.Computer.FileSystem.WriteAllText("c:\savelocation", TextBox1.Text, False
如何解决 retun caret 问题?还, 我将如何让用户选择保存位置而不是代码的一部分?
问题 3:如何将用户在另存为对话框中指定的文件路径放入变量中?
任何帮助,即使只是回答我的一个问题,也将不胜感激! 谢谢!
【问题讨论】:
标签: vb.net dialog save streamwriter save-as