Public Class Form1

Private Sub NewToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click
    RichTextBox1.Clear()
End Sub

Private Sub OpenToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles OpenToolStripMenuItem.Click
    Dim openFileDialog1 As New OpenFileDialog()
    openFileDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
    openFileDialog1.FilterIndex = 1
    openFileDialog1.RestoreDirectory = True

    If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
        Try
            Dim sr As New System.IO.StreamReader(openFileDialog1.FileName)
            RichTextBox1.Text = sr.ReadToEnd()
            sr.Close()
        Catch ex As Exception
            MessageBox.Show("Error: Could not read file from disk. Original error: " & ex.Message)
        End Try
    End If
End Sub

Private Sub SaveToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SaveToolStripMenuItem.Click
    If Not String.IsNullOrEmpty(RichTextBox1.Text) Then
        If Not String.IsNullOrEmpty(SaveFileDialog1.FileName) Then
            My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName, RichTextBox1.Text, False)
        Else
            SaveAsToolStripMenuItem.PerformClick()
        End If
    End If
End Sub

Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SaveAsToolStripMenuItem.Click
    Dim saveFileDialog1 As New SaveFileDialog()

    saveFileDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
    saveFileDialog1.FilterIndex = 1
    saveFileDialog1.RestoreDirectory = True

    If saveFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
        My.Computer.FileSystem.WriteAllText(saveFileDialog1.FileName, RichTextBox1.Text, False)
        saveFileDialog1.FileName = saveFileDialog1.FileName
    End If
End Sub

Private Sub ExitToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ExitToolStripMenuItem.Click
    Me.Close()
End Sub

Private Sub UndoToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles UndoToolStripMenuItem.Click
    RichTextBox1.Undo()
End Sub

Private Sub CutToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CutToolStripMenuItem.Click
    RichTextBox1.Cut()
End Sub

Private Sub CopyToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CopyToolStripMenuItem.Click
    RichTextBox1.Copy()
End Sub

Private Sub PasteToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles PasteToolStripMenuItem.Click
    RichTextBox1.Paste()
End Sub

Private Sub DeleteToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles DeleteToolStripMenuItem.Click
    RichTextBox1.SelectedText = ""
End Sub

Private Sub FontToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles FontToolStripMenuItem.Click
    Dim fontDialog1 As New FontDialog()

    If fontDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
        RichTextBox1.Font = fontDialog1.Font
    End If
End Sub

Private Sub AboutNotepadToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles AboutNotepadToolStripMenuItem.Click
    MessageBox.Show("Notepad" & vbCrLf & "Version 1.0" & vbCrLf & "©2022 Microsoft Corporation. All rights reserved.")
End Sub

Private Sub SelectAllToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectAllToolStripMenuItem.Click
    RichTextBox1.SelectAll()
End Sub

End Class

提示:本软件由VS2010旗舰版的VB.NET版本编写,对于其他VS2019或者VS2020都可能无法正常使用。请先确认VS2010旗舰版的VB.NET能正常使用。
有需要可以在下面这个地址下载源代码文件。

https://download.csdn.net/download/qq_32257509/89435571

06-27 07:41