469,596 Members | 2,241 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,596 developers. It's quick & easy.

Font with Bold and italic

Hi, i'm using a richtextbox named r1, and i want to write in Bold and
italic, i tryed this for bold and it work

Dim f As New Font("Verdana", 30, FontStyle.Bold)
r1.Font = f
r1.Text = "Hello"

but if i try this for bold and italic it doesn't work

Dim f As New Font("Verdana", 30, FontStyle.Bold And FontStyle.Italic)
r1.Font = f
r1.Text = "Hello"

so how can i write in bold and italic?
Thx :)

Jul 31 '06 #1
4 12620

paraidy napisal(a):
Hi, i'm using a richtextbox named r1, and i want to write in Bold and
italic, i tryed this for bold and it work

Dim f As New Font("Verdana", 30, FontStyle.Bold)
r1.Font = f
r1.Text = "Hello"

but if i try this for bold and italic it doesn't work

Dim f As New Font("Verdana", 30, FontStyle.Bold And FontStyle.Italic)
r1.Font = f
r1.Text = "Hello"

so how can i write in bold and italic?
Thx :)
Hi,

Try this code

Dim NewFont As New Font(RichTextBox1.Font, FontStyle.Bold +
FontStyle.Italic)
RichTextBox1.Font = NewFont

Hope this help.
Regards,
sweet_dreams

Jul 31 '06 #2

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 :)

Jul 31 '06 #3

"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
Jul 31 '06 #4

Mythran wrote:
"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
Understood now, thx a lot :)

Aug 9 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Coder Droid | last post: by
1 post views Thread by Jyothi | last post: by
1 post views Thread by Fei Li | last post: by
1 post views Thread by shachar | last post: by
2 posts views Thread by Adam Honek | last post: by
1 post views Thread by FLEMEF | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.