'打开
Private Sub MenuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuOpen.Click
RichTextBox1.Clear()
OpenFileDialog1.Filter = "文本文件(*.txt)|*.txt|rtf文件(*.rtf)|*.rtf|所有文件(*.*)|*.*"
OpenFileDialog1.FileName = RichTextBox1.Name
OpenFileDialog1.FilterIndex = 1
OpenFileDialog1.InitialDirectory = "g:\"
OpenFileDialog1.RestoreDirectory = False
If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
'Select Case OpenFileDialog1.FilterIndex
'Case 1
RichTextBox1.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText)
' Case 2
'RichTextBox1.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.RichText)
'End Select
End If
Me.Text = "我的记事本 - " & OpenFileDialog1.FileName
End Sub
'保存
Private Sub MenuSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuSave.Click
SaveFileDialog1.Filter = "文本文件(*.txt)|*.txt|rtf文件(*.rtf)|*.rtf|所有文件(*.*)|*.*"
SaveFileDialog1.FileName = RichTextBox1.Name
SaveFileDialog1.FilterIndex = 1
SaveFileDialog1.InitialDirectory = "g:\"
SaveFileDialog1.RestoreDirectory = True
If SaveFileDialog1.ShowDialog = System.Windows.Forms.DialogResult.OK Then
'Select Case SaveFileDialog1.FilterIndex
' Case 1
RichTextBox1.SaveFile(SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText)
' Case 2
'RichTextBox1.SaveFile(SaveFileDialog1.FileName, RichTextBoxStreamType.RichText)
'End Select
End If
End Sub