Der Pc-Blog ist umgezogen. Du findest ihn ab jetzt unter www.meinpc-blog.de

Samstag, 22. Januar 2011

Visual Basic Tutorialreihe Teil 6 - NotePad für Arme

In diesem Teil meiner Video-Tutorial Reihe zeige ich euch, wie ihr in einer RichTextBox selektierten Text Fett/Kursiv/Unterstrichen macht und die Schriftgröße und Schriftart ändert.



Bilder:
zu jeder Nutzung freigegeben
Hier zum Downloaden klicken

Code:

Imports System.IO

Public Class Form1

    Private Sub ÖffnenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ÖffnenToolStripMenuItem.Click

        RichTextBox1.Text = ""

        Dim sr As New StreamReader("Datei.txt")

        While Not sr.EndOfStream
            RichTextBox1.Text = RichTextBox1.Text & sr.ReadLine & vbCrLf
        End While

        sr.Close()

    End Sub

    Private Sub SpeichernToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SpeichernToolStripMenuItem.Click

        Dim sw As New StreamWriter("Datei.txt")

        For Each line As String In RichTextBox1.Lines
            sw.WriteLine(line)
        Next

        sw.Close()

    End Sub

    Private Sub ÜberToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ÜberToolStripMenuItem.Click
        Form2.Show()
    End Sub

    Private Sub FettToolStrip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FettToolStrip.Click
        If Not RichTextBox1.SelectionFont.Style = FontStyle.Bold Then
            RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Bold)
        Else
            RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Regular)
        End If
    End Sub

    Private Sub KursivToolStrip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KursivToolStrip.Click
        If Not RichTextBox1.SelectionFont.Style = FontStyle.Italic Then
            RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Italic)
        Else
            RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Regular)
        End If
    End Sub

    Private Sub UnterstrichenToolStrip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UnterstrichenToolStrip.Click
        If Not RichTextBox1.SelectionFont.Style = FontStyle.Underline Then
            RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Underline)
        Else
            RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Regular)
        End If
    End Sub

    Private Sub SchriftArtCombo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SchriftArtCombo.SelectedIndexChanged

        Try
            RichTextBox1.SelectionFont = New Font(New FontFamily(SchriftArtCombo.Text), Convert.ToInt32(SchriftGrößeCombo.Text), FontStyle.Regular)
        Catch
        End Try

        RichTextBox1.Focus()

    End Sub

    Private Sub SchriftGrößeCombo_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SchriftGrößeCombo.TextChanged

        Try
            RichTextBox1.SelectionFont = New Font(RichTextBox1.Font.Name, Convert.ToInt32(SchriftGrößeCombo.Text), RichTextBox1.Font.Style, RichTextBox1.Font.Unit)
        Catch
        End Try

        RichTextBox1.Focus()

    End Sub

End Class

Keine Kommentare:

Kommentar veröffentlichen