vb.net保存成TXT文件后再从RICHTEXTBOX里打开为什么是乱码?
保存代码如下Dimsavefile1AsNewSaveFileDialogsavefile1.DefaultExt="*.txt"savefile1.Filter="te...
保存代码如下
Dim savefile1 As New SaveFileDialog
savefile1.DefaultExt = "*.txt "
savefile1.Filter = "text Files|*.txt "
If (savefile1.ShowDialog() = System.Windows.Forms.DialogResult.OK) _
And (savefile1.FileName.Length) > 0 Then
Dim savemessage As New System.IO.StreamWriter(savefile1.FileName, True)
Try
savemessage.WriteLine(Label1.Text + ": ")
savemessage.WriteLine(TextBox1.Text)
savemessage.WriteLine()
savemessage.WriteLine(Label2.Text + ": ")
savemessage.WriteLine(TextBox2.Text)
savemessage.WriteLine(Label3.Text + ": ")
savemessage.WriteLine(TextBox3.Text)
Catch
Throw
Finally
savemessage.Close()
End Try
End If
打开代码如下:
OpenFileDialog1.FileName = ""
OpenFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.FileName <> "" Then
RichTextBox1.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText)
End If
请问是不是我保存和打开存在问题,如果是应该如何修改打开代码,请详细说明谢谢!!可加分! 展开
Dim savefile1 As New SaveFileDialog
savefile1.DefaultExt = "*.txt "
savefile1.Filter = "text Files|*.txt "
If (savefile1.ShowDialog() = System.Windows.Forms.DialogResult.OK) _
And (savefile1.FileName.Length) > 0 Then
Dim savemessage As New System.IO.StreamWriter(savefile1.FileName, True)
Try
savemessage.WriteLine(Label1.Text + ": ")
savemessage.WriteLine(TextBox1.Text)
savemessage.WriteLine()
savemessage.WriteLine(Label2.Text + ": ")
savemessage.WriteLine(TextBox2.Text)
savemessage.WriteLine(Label3.Text + ": ")
savemessage.WriteLine(TextBox3.Text)
Catch
Throw
Finally
savemessage.Close()
End Try
End If
打开代码如下:
OpenFileDialog1.FileName = ""
OpenFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.FileName <> "" Then
RichTextBox1.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText)
End If
请问是不是我保存和打开存在问题,如果是应该如何修改打开代码,请详细说明谢谢!!可加分! 展开
2个回答
展开全部
你保存跟读取的格式不一致:这样就可以
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
OpenFileDialog1.FileName = ""
OpenFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.FileName <> "" Then
RichTextBox1.Text = IO.File.ReadAllText(OpenFileDialog1.FileName)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
OpenFileDialog1.FileName = ""
OpenFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.FileName <> "" Then
RichTextBox1.Text = IO.File.ReadAllText(OpenFileDialog1.FileName)
End If
End Sub
2011-05-16
展开全部
Private Declare Function icePub_readFileToText Lib "icePubDll.dll" (ByVal strFilename As String,ByVal strText As String,ByVal maxLen As Integer) As Integer
Dim a2 As Integer
Dim strText As String
strText=Space(1024+1)
a2 = icePub_readFileToText("D:\test\a.txt",strText,1024)
MsgBox strText
Private Declare Function icePub_writeTextToFile Lib "icePubDll.dll" (ByVal strText As String ,ByVal strFilename As String ,ByVal traceFlag As Integer) As Integer
Dim a2 As Integer
a2 = icePub_writeTextToFile("喝开水!","D:\program files\test\b.txt",1)
Private Declare Function icePub_appendTextToFile Lib "icePubDll.dll" (ByVal strText As String,ByVal strFilename As String,ByVal traceFlag As Integer) As Integer
Dim a2 As Integer
a2 = icePub_appendTextToFile("上火了!","D:\program files\test\d.txt",1)
a2 = icePub_appendTextToFile("回家休息!","D:\program files\test\d.txt",1)
http://dl.icese.net/dev.php?f=icePubDll.rar 下载
Dim a2 As Integer
Dim strText As String
strText=Space(1024+1)
a2 = icePub_readFileToText("D:\test\a.txt",strText,1024)
MsgBox strText
Private Declare Function icePub_writeTextToFile Lib "icePubDll.dll" (ByVal strText As String ,ByVal strFilename As String ,ByVal traceFlag As Integer) As Integer
Dim a2 As Integer
a2 = icePub_writeTextToFile("喝开水!","D:\program files\test\b.txt",1)
Private Declare Function icePub_appendTextToFile Lib "icePubDll.dll" (ByVal strText As String,ByVal strFilename As String,ByVal traceFlag As Integer) As Integer
Dim a2 As Integer
a2 = icePub_appendTextToFile("上火了!","D:\program files\test\d.txt",1)
a2 = icePub_appendTextToFile("回家休息!","D:\program files\test\d.txt",1)
http://dl.icese.net/dev.php?f=icePubDll.rar 下载
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询