用VB.NET做一个记事本

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


            OpenFileDialog1.ShowDialog()

        RichTextBox1.LoadFile(Me.OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText)
      







    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim fname As String
        Me.SaveFileDialog1.ShowDialog()
        fname = Me.SaveFileDialog1.FileName


        If (fname <> "") Then



            If (Me.OpenFileDialog1.FilterIndex = 1) Then
                Me.RichTextBox1.SaveFile(fname, RichTextBoxStreamType.PlainText)
            Else
                Me.RichTextBox1.SaveFile(fname, RichTextBoxStreamType.RichText)



            End If

        End If




    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Me.SaveFileDialog2.ShowDialog()

        If (Me.OpenFileDialog1.FileName <> "") Then


            If (Me.OpenFileDialog1.FilterIndex = 1) Then

                Me.RichTextBox1.SaveFile(Me.SaveFileDialog2.FileName, RichTextBoxStreamType.PlainText)
            Else
                Me.RichTextBox1.SaveFile(Me.SaveFileDialog2.FileName, RichTextBoxStreamType.RichText)

            End If

        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.FontDialog1.Font = Me.RichTextBox1.SelectionFont
        If (Me.FontDialog1.ShowDialog() = Me.DialogResult.OK) Then
            Me.RichTextBox1.SelectionFont = Me.FontDialog1.Font

        End If
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Me.ColorDialog1.Color = Me.RichTextBox1.SelectionColor
        If (Me.ColorDialog1.ShowDialog() = Me.DialogResult.OK) Then

         
            Me.RichTextBox1.SelectionColor = Me.ColorDialog1.Color
        End If


    End Sub

    Private Sub 打开ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打开ToolStripMenuItem.Click
        Try
            Dim str As String
            Dim typel As System.Windows.Forms.RichTextBoxStreamType
            OpenFileDialog1.ShowDialog()
            str = OpenFileDialog1.FileName
            RichTextBox1.LoadFile(str, RichTextBoxStreamType.PlainText)
        Catch ex As Exception
        End Try
    End Sub

    Private Sub 保存ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 保存ToolStripMenuItem.Click
        Me.SaveFileDialog1.ShowDialog()

        If (Me.SaveFileDialog1.FileName <> "") Then



            If (Me.OpenFileDialog1.FilterIndex = 1) Then
                Me.RichTextBox1.SaveFile(Me.SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText)
            Else

                Me.RichTextBox1.SaveFile(Me.SaveFileDialog1.FileName, RichTextBoxStreamType.RichText)

            End If

        End If

    End Sub

    Private Sub 另存为ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 另存为ToolStripMenuItem.Click
        Me.SaveFileDialog1.ShowDialog()

        If (Me.OpenFileDialog1.FileName <> "") Then



            If (Me.OpenFileDialog1.FilterIndex = 1) Then
                Me.RichTextBox1.SaveFile(Me.SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText)
            Else
                Me.RichTextBox1.SaveFile(Me.SaveFileDialog1.FileName, RichTextBoxStreamType.RichText)

            End If

        End If
    End Sub

    Private Sub 退出ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 退出ToolStripMenuItem.Click
        End

    End Sub

    Private Sub 字体ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 字体ToolStripMenuItem.Click
        Me.FontDialog1.Font = Me.RichTextBox1.SelectionFont
        If (Me.FontDialog1.ShowDialog() = Me.DialogResult.OK) Then
            Me.RichTextBox1.SelectionFont = Me.FontDialog1.Font

        End If
    End Sub

    Private Sub 颜色ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 颜色ToolStripMenuItem.Click
        Me.ColorDialog1.Color = Me.RichTextBox1.SelectionColor
        If (Me.ColorDialog1.ShowDialog() = Me.DialogResult.OK) Then

            Me.RichTextBox1.SelectionColor = Me.ColorDialog1.Color
        End If

    End Sub

    Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk

    End Sub
End Class

阅读更多

没有更多推荐了,返回首页