Hi. I am working on a very simple text editor. I wonder how to apply more than 1 font style (eg. Bold + Underline, Bold + Italic, Italic + Underline) on selected text in a RichTextBox object?
I created a button to bold the selected text, and the codes:
Private Sub BoldTextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BoldTextButton.Click
'Create new Font object and set its properties
Dim ReplaceFont As New Font(Me.DocContentRichTextBox.SelectionFont, FontStyle.Bold)
'Apply ReplaceFont onto selected text
Me.DocContentRichTextBox.SelectionFont = ReplaceFont
End Sub
This piece of code does work, but it will cancel the current font style, and make the selected text become bold ONLY; if the original text has italic font style, after pressing the button, the text will have bold font style only.
So, how do I apply "append" font style in VB.NET? Thanks very much.
Edit: I have found a solution on the Internet... I just have to modify my codes a little bit:
Private Sub BoldTextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BoldTextButton.Click
'Get font of selected text
Dim selectedTextFont As Font = Me.DocContentRichTextBox.SelectionFont
'Create new Font object and set its properties
Dim ReplaceFont As New Font(selectedTextFont, selectedTextFont.Style Xor FontStyle.Bold)
'Apply ReplaceFont onto selected text
Me.DocContentRichTextBox.SelectionFont = ReplaceFont
End Sub
Here is my new question: Why do I have to use XOR, rather than AND, between the FontStyle? I thought using AND is to "adding up" the FontStyle.
Hello,
There were some claims he was involved in the malware scene in Montréal in the 00's, but I don't think they were ever substantiated.
Regards,
Aryeh Goretsky
i had to pay 20. Only because my PS4 wouldn't transfer it to PS5. Then it would get to 24% when using the disc and fail. So, I bought the online version only.
Microsoft Edge comes pre-installed with Windows 11 and it's a great browser, so why not use it? Not everyone is trying to run away from Google, sometimes people just want convenience and less friction.
Question
Gundamdriver
Hi. I am working on a very simple text editor. I wonder how to apply more than 1 font style (eg. Bold + Underline, Bold + Italic, Italic + Underline) on selected text in a RichTextBox object?
I created a button to bold the selected text, and the codes:
This piece of code does work, but it will cancel the current font style, and make the selected text become bold ONLY; if the original text has italic font style, after pressing the button, the text will have bold font style only.
So, how do I apply "append" font style in VB.NET? Thanks very much.
Edit: I have found a solution on the Internet... I just have to modify my codes a little bit:
Here is my new question: Why do I have to use XOR, rather than AND, between the FontStyle? I thought using AND is to "adding up" the FontStyle.
Edited by GundamdriverLink to comment
https://www.neowin.net/forum/topic/680536-vbnet-applying-more-than-1-font-style/Share on other sites
1 answer to this question
Recommended Posts