473,396 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 13310

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Coder Droid | last post by:
I'm trying my first table-less site, and I've bumped my head up against a wall. I can't change the font size within a div. Real quick, my style sheet has: -------------------------------------...
1
by: Jyothi | last post by:
Hi, In a rich text box , I select a text and make it Bold it turns bold and i make it italic the bold nature is lost.... I do not want this to happen..how do i avoid this? I want the...
1
by: shachar | last post by:
hi all. i have a grid ocx i'm using, and i have to set it's font to an integer value returning from a font object. when i wrote : Dim f As System.Drawing.Font al it's propertys are readonly. how...
7
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and...
2
by: Adam Honek | last post by:
Okay, Assinging the font and its style (bold, italic etc.) using the font dialog is easy such as: FontDialog1.ShowDialog() txtEmailBody.SelectionFont = FontDialog1.Font But how does one...
0
by: the.tinapatel | last post by:
Guys, I want the user to be able to select font (such as Bold, Italic, underline) and stuff like that from a dropdown list) and then I wanna apply these properties to all my page (all text). Now...
1
by: FLEMEF | last post by:
Hello All, I'm not very good at Java... With this piece of Java code, how could I modify the StyleOptions.java program to allow the user to specify the size of the font, while using the text...
1
!NoItAll
by: !NoItAll | last post by:
So - I have some text in an RTF control. I want the user to be able to highlight text and apply an attribute. The following code is placed into a button called BOLD and seems to work nicely: ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.