4) “保存”按钮单击事件代码
Private Sub BtSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtSave.Click
‘保存听写记录ToolStripMenuItem.Click
Dim FilePath As String
If Me.TxtListen.Text Is Nothing Then
MsgBox("当前听写区为空", MsgBoxStyle.OkOnly, "PC复读机")
Exit Sub
Else
SaveFileDialog1.ShowDialog()
SaveFileDialog1.Title = "保存填写记录"
SaveFileDialog1.CheckFileExists = False
SaveFileDialog1.CheckPathExists = True
SaveFileDialog1.Filter = "文本文件(*.txt)|*.txt"
FilePath = SaveFileDialog1.FileName
' With Me.SaveFileDialog1
'.Title = "保存填写记录"
' .CheckFileExists = False
' .CheckPathExists = True
' .Filter = "文本文件(*.txt)|*.txt"
' ' If ShowDialog() = Windows.Forms.DialogResult.Cancel Then
' ' Exit Sub
' 'End If
' FilePath = .FileName
' End With
' Dim MyStreamWriter As IO.StreamWriter
' MyStreamWriter = IO.File.CreateText(FilePath)
' Dim MyOutput As String
' While MyOutput Is Nothing
' MyOutput = TxtListen.Text
' MyStreamWriter.WriteLine(MyOutput)
' TxtListen.Text = TxtListen.Text.Remove(0, MyOutput.Length)
' End While
' MyStreamWriter.Close()
My.Computer.FileSystem.WriteAllText(FilePath, TxtListen.Text, True)
End If
End Sub
|