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: コードをテキスト ファイルの特定の場所に書き込むことはできますが、リターン キャレットが失われ、次を使用してすべて 1 行でテキスト ファイルに保存されます。
My.Computer.FileSystem.WriteAllText("c:\savelocation", TextBox1.Text, False
戻りキャレットの問題を修正するにはどうすればよいですか? また、コードの一部ではなく、ユーザーが保存場所を選択できるようにするにはどうすればよいですか?
問題 3: ユーザーが [名前を付けて保存] ダイアログで指定したファイル パスを変数に取得するにはどうすればよいですか?
私の質問の1つに対する答えだけでも、どんな助けでも大歓迎です! ありがとう!