Sign in to follow this  

Bold, Italic & Underline

This topic is 4711 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am using VB.NET and I'm trying to make simple text editor. it should have an option to make your text Bold, Italic and Underline. But I'm having a problem when I want to have my text Bold AND Italic (2 options together). Here is the code for 3 subs, each for one option.
     Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked Then
            RichTextBox1.Font = New Font(IzabraniFont_Izvan, IzabranaVelicina_Izvan, Fontstyle.Bold, 0)
        Else
            RichTextBox1.Font = New Font(IzabraniFont_Izvan, IzabranaVelicina_Izvan, Fontstyle.Regular, 0)
        End If
    End Sub

   Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
        If CheckBox2.Checked Then
            RichTextBox1.Font = New Font(IzabraniFont_Izvan, IzabranaVelicina_Izvan, FontStyle.Italic, 0)
        Else
            RichTextBox1.Font = New Font(IzabraniFont_Izvan, IzabranaVelicina_Izvan, FontStyle.Regular, 0)
        End If
    End Sub

    Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
        If CheckBox3.Checked Then
            RichTextBox1.Font = New Font(IzabraniFont_Izvan, IzabranaVelicina_Izvan, FontStyle.Underline, 0)
        Else
            RichTextBox1.Font = New Font(IzabraniFont_Izvan, IzabranaVelicina_Izvan, FontStyle.Regular, 0)
        End If
    End Sub

Do you have any ide how to fix that? Thanks, -rex

Share this post


Link to post
Share on other sites
Create a new sub that handels all three and use if statements to check for combos

If CheckBox1.Checked AND CheckBox2.Checked Then
RichTextBox1.Font = New Font(IzabraniFont_Izvan, IzabranaVelicina_Izvan, Fontstyle.Bold | Fontstyle.Italic, 0)
Else
RichTextBox1.Font = New Font(IzabraniFont_Izvan, IzabranaVelicina_Izvan, Fontstyle.Regular, 0)
End If
If CheckBox1.Checked AND CheckBox3.Checked Then
RichTextBox1.Font = New Font(IzabraniFont_Izvan, IzabranaVelicina_Izvan, Fontstyle.Bold Fontstyle.Underline, 0)
Else
RichTextBox1.Font = New Font(IzabraniFont_Izvan, IzabranaVelicina_Izvan, Fontstyle.Regular, 0)
End If
If CheckBox2.Checked AND CheckBox3.Checked Then
RichTextBox1.Font = New Font(IzabraniFont_Izvan, IzabranaVelicina_Izvan, Fontstyle.Italic | Fontstyle.Underline, 0)
Else
RichTextBox1.Font = New Font(IzabraniFont_Izvan, IzabranaVelicina_Izvan, Fontstyle.Regular, 0)
End If

should be that simple but then again it has been a while since i did any VB programming so....

Share this post


Link to post
Share on other sites

This topic is 4711 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this