打开文件:
[CODE]Dim myodf As New OpenFileDialog() '实例化一个打开文件对话的对象
myodf.Filter = "*所有文件|*|.txt|*.txt|.cs|*.cs|.vb|*.vb|.htm|*.htm"
If myodf.ShowDialog() = Windows.Forms.DialogResult.OK Then '如果点击“打开”按钮
Dim filePath As String
filePath = myodf.FileName
If filePath = "" Then
Return
End If
Try
Me.rtxt_Main.LoadFile(filePath, RichTextBoxStreamType.PlainText)
Catch
MessageBox.Show("文件类型不正确!", "系统提示:", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try[/CODE]
保存文件:
[CODE]Dim mysfd As New SaveFileDialog()
mysfd.Filter = "*所有文件|*|.txt|*.txt|.cs|*.cs|.vb|*.vb|.htm|*.htm"
If mysfd.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim fileName As String
fileName = mysfd.FileName
If fileName = "" Then
Return
End If
Me.rtxt_Main.SaveFile(fileName, RichTextBoxStreamType.PlainText)
End If[/CODE]