lenovo翻译:帮个忙!!!

来源:百度文库 编辑:高校问答 时间:2024/04/29 12:18:53
如何将VB中文本框中的文本保存为一个文本文件,且编码为Unicode?(重要的是后者)

设置个按钮:然后在Form里面添加 SaveFileDialog控件
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem7.Click
SaveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
If TextBox1.Text.Length > 0 Then
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
'如果点击OK
Dim fs As New FileStream(SaveFileDialog1.FileName, FileMode.Create)
Dim fw As New StreamWriter(fs, Encoding.Default)
fw.BaseStream.Seek(0, SeekOrigin.End)
fw.WriteLine(TextBox1.Text)
fw.Close()
Else
'如果点击取消
TextBox1.Focus()
End If
Else
MsgBox("抱歉,没有什么内容可保存!")
TextBox1.Focus()
End If
End Sub