Vb.net – Make Font Bold/Italic/Underline Visual Basic

vb.net

Ok I already have a Font Dialog that changes the font of the richtextbox and it works (although I don't know how to make the apply button of the dialog work)

I also made 4 buttons for Bold, Underline, Strikethrough, and Italic.

The method I have found most people using is

Dim boldf as NewFont(....) 

and then applying it to the selected text.

Problem with that is that it changes the font to only Bold, it doesn't add it to the existing style.

Please advise.

Best Answer

Private Sub andlowitwasbold_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles andlowitwasbold.Click
    If RichTextBox1.SelectionFont.Bold Then 'its already bold, so set it to regular
        RichTextBox1.SelectionFont = New Font(RichTextBox1.Font.FontFamily, RichTextBox1.Font.Size, FontStyle.Regular)
    Else 'make it bold
        RichTextBox1.SelectionFont = New Font(RichTextBox1.Font.FontFamily, RichTextBox1.Font.Size, FontStyle.Bold)
    End If
End Sub
Related Topic