"paraidy" <sa*******@tiscali.itwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
>
sweet_dreams ha scritto:
>Hi,
Try this code
Dim NewFont As New Font(RichTextBox1.Font, FontStyle.Bold +
FontStyle.Italic)
RichTextBox1.Font = NewFont
Yes it worked, thx a lot :)
The + works, but what you are doing is a bitwise operation against an
enumeration value. The FontStyle has the FlagsAttribute associated with it
so we know we can treat them as binary flags. (look up the FlagsAttribute
for more information on the following information)
What it should be is:
Dim NewFont As New Font(RichTextBox1.Font, FontStyle.Bold Or
FontStyle.Italic)
RichTextBox1.Font = NewFont
The reason your FontStyle.Bold And FontStyle.Italic didn't work is:
FontStyle.Bold = 1 = 0001 ' in binary
FontStyle.Italic = 2 = 0010 ' in binary
So...the result of your AND statement = 0001 And 0010 = 0000 (all off).
What you want is an OR = 0001 Or 0010 = 0011 (last two bits which represents
the two flags, Bold and Italic, turned on). It just so happens that using
regular addition on those values will give you the same result :)
HTH you understand it better ... for future reference,
Mythran