|
-
Nov 14th, 2005, 06:14 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] How to make a font bold and italic ?
I'm writing a little word processor app in VS2005 as a bit of an exercise.
The problem I'm having is with setting font styles for selected text, I'm using a RichTextBox and I have both 'Bold' and 'Italic' buttons on the toolbar, if I select some text and click 'Bold', the selected text alters state i.e if it's already bold it becomes regular and visa versa, the same goes for the 'Italic' button.
The thing I cant figure out is how to make the text both bold and italic, say I select some text that is already bold 'TEST TEXT ' and I click the italic button, it changes to 'TEST TEXT '. I cant see a FontStyle of .BoldItalic so I'm pretty stumped
Is there an easy way of doing this ?
-
Nov 14th, 2005, 06:31 PM
#2
Re: How to make a font bold and italic ?
Hi,
I'm using VS.Net 2003.
But you can try this:
RichTextBox.SelectionStart = RichTextBox.Find
Dim Italic as New font(RichTextBox.Font, Fontstyle.Italic
RichTextBox.SelectionFont = ItalicFont
and
RichTextBox.SelectionFont = RichTextBox.Find
Dim BoldFont As New Font(RichTextBox.Font, FontStyle.Bold)
RichTextBox.SelectionFont = BoldFont
Hope it helps you!
sparrow1
-
Nov 14th, 2005, 06:33 PM
#3
Re: How to make a font bold and italic ?
The FontStyle enumeration has been declared with the Flags attribute, which means you can create combined values with a bitwise Or:
VB Code:
FontStyle.Bold Or FontStyle.Italic
will create a FontStyle that is both Bold and Italic. It may seem strange to use Or when logically you mean And, but this is a bitwise operation. Each individual value is a series of bits that only has a single bit set. The bitwise Or creates a new value that has both the bit for Bold and the bit for Italic set.
-
Nov 14th, 2005, 06:34 PM
#4
Re: How to make a font bold and italic ?
Actually, you can set them both with one statement.
Dim UsedFont as new font ("Arial", 12, FontStyles.Bold Or FontStyles.Italic)
The Or may mislead you unless you think of it like a Bitwise Or operation on the binary equivalent of those Enumerated constants.
If you don't know the current status of the font, you can probably use:
Dim UsedFont as new font ("Arial", 12, RichTextBox.Font Or FontStyles.Italic)
to for example add italics to the current format.
Bill
-
Nov 14th, 2005, 06:35 PM
#5
Re: How to make a font bold and italic ?
Arg, now who's looking in the mirror :P
Bill
-
Nov 14th, 2005, 06:40 PM
#6
Re: How to make a font bold and italic ?
 Originally Posted by conipto
Arg, now who's looking in the mirror :P
Bill
I'm sure it was a worthwhile glance anyway.
-
Nov 15th, 2005, 03:38 AM
#7
Thread Starter
Hyperactive Member
Re: How to make a font bold and italic ?
Once again, thanks for all your help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|