473,809 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Itali c)
r1.Font = f
r1.Text = "Hello"

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

Jul 31 '06 #1
4 13376

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.Itali c)
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(RichTextBo x1.Font, FontStyle.Bold +
FontStyle.Itali c)
RichTextBox1.Fo nt = NewFont

Hope this help.
Regards,
sweet_dreams

Jul 31 '06 #2

sweet_dreams ha scritto:
Hi,

Try this code

Dim NewFont As New Font(RichTextBo x1.Font, FontStyle.Bold +
FontStyle.Itali c)
RichTextBox1.Fo nt = NewFont

Yes it worked, thx a lot :)

Jul 31 '06 #3

"paraidy" <sa*******@tisc ali.itwrote in message
news:11******** *************@b 28g2000cwb.goog legroups.com...
>
sweet_dreams ha scritto:
>Hi,

Try this code

Dim NewFont As New Font(RichTextBo x1.Font, FontStyle.Bold +
FontStyle.Ital ic)
RichTextBox1.F ont = 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(RichTextBo x1.Font, FontStyle.Bold Or
FontStyle.Itali c)
RichTextBox1.Fo nt = NewFont

The reason your FontStyle.Bold And FontStyle.Itali c didn't work is:

FontStyle.Bold = 1 = 0001 ' in binary
FontStyle.Itali c = 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*******@tisc ali.itwrote in message
news:11******** *************@b 28g2000cwb.goog legroups.com...

sweet_dreams ha scritto:
Hi,

Try this code

Dim NewFont As New Font(RichTextBo x1.Font, FontStyle.Bold +
FontStyle.Itali c)
RichTextBox1.Fo nt = 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(RichTextBo x1.Font, FontStyle.Bold Or
FontStyle.Itali c)
RichTextBox1.Fo nt = NewFont

The reason your FontStyle.Bold And FontStyle.Itali c didn't work is:

FontStyle.Bold = 1 = 0001 ' in binary
FontStyle.Itali c = 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
14533
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: ------------------------------------- body { font: 8pt "face" } #nav {float: left; width: 144px; } #test { font: 12pt; font-weight: bold } -------------------------------------
1
2486
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 style to be both italic and bold or whatever is being done on the selected text.i.e just exactly how the Word behaves..
1
1144
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 can i set it's Bold,Underline etc..
7
2978
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 already formatted as "Shopping" ---Bold "for" -----Regular Now I want to underline whole text by preserving old style i.e. Bold and
2
2870
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 change the selected text to bold, italic or underlined without using the font dialog?
0
1404
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 I'm doing something like this: string font = string.Empty; switch(ddl2.SelectedItem.Text) {
1
8644
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 field to obtain the user’s input. Thanks. ----------------------------------------------------------------- import javax.swing.*; import java.awt.*; import java.awt.event.*;
1
1230
!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: If rtfText.SelectedText.Length > 0 Then rtfText.SelectionFont = New Font(rtfText.SelectionFont, FontStyle.Bold) End If The code above will turn the selected text bold. Great! But then the user selects the Same text and...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9601
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10637
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9199
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7660
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3014
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.