473,325 Members | 2,872 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,325 software developers and data experts.

How to preserve font properties while changing some other properties.

Hi All,

I am using a richTextBox control for text editing purpose. I have written
following procedure which change the font style of richTextBox.

Dim f as font = rtbData.selectionFont()

rtbData.SelectionFont = New Font(f, f.Style + (IIf(f.Bold, FontStyle.Bold
* -1, FontStyle.Bold)))
Using above code I am able to preserve old font style while changing style
like Bold.

But, How to change the font name and size property.

Thanks in advance
Sakharam Phapale

Nov 21 '05 #1
3 1827

Hi All,

I got the answer as follows.
Dim fOld As Font = rtbData.SelectionFont
Dim fontFamily As New FontFamily(FontFamilyName)

rtbData.SelectionFont = New Font(fontFamily, fOld.Size)

Dim fNew As Font = rtbData.SelectionFont

rtbData.SelectionFont = New Font(fNew, fOld.Style)
Thanks
Sakharam Phapale

"Sakharam Phapale" <sp******@annetsite.com> wrote in message
news:Om*************@TK2MSFTNGP11.phx.gbl...
Hi All,

I am using a richTextBox control for text editing purpose. I have written
following procedure which change the font style of richTextBox.

Dim f as font = rtbData.selectionFont()

rtbData.SelectionFont = New Font(f, f.Style + (IIf(f.Bold, FontStyle.Bold
* -1, FontStyle.Bold)))
Using above code I am able to preserve old font style while changing style
like Bold.

But, How to change the font name and size property.

Thanks in advance
Sakharam Phapale

Nov 21 '05 #2
Sakharam,

To show you the use of the boolean "OR" in this, see this old snippet from
me.

\\\
Me.Label1.Font = New Font(Me.Label1.Font, Me.Label1.Font.Style Or
FontStyle.Bold)
///

I hope this helps?

Cor
Nov 21 '05 #3
Hello,

Your solution works fine for font style. But what about following situation,
I want to change font of richTextBox contents, which is having multiple
styles.
look at following example

richTextBox.Text = "This is just a test example"
"This" ---Times New Roman, Bold, 10
"is"-------arial, Regular,8
"just"-----Courier, Regular,9

Now, I select "This is just" in richTextBox and want to change the font size
to 10 of selected text.

How to accomplish this?
I have written following code. But it doesn't work properly in above
scenario.

Private sub ChangeFont(FontSize as integer)
Dim fOld As Font = rtbData.SelectionFont

rtbData.SelectionFont = New Font(fOld.FontFamily, FontSize,
fOld.Style)

End Sub

In above scenario fOld returns as Nothing so I can't used this.
Thanks and Regards
Sakharam Phapale


"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Sakharam,

To show you the use of the boolean "OR" in this, see this old snippet from
me.

\\\
Me.Label1.Font = New Font(Me.Label1.Font, Me.Label1.Font.Style Or
FontStyle.Bold)
///

I hope this helps?

Cor

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Cengiz Ulku | last post by:
Hi all, I know now how to change the font name of a RTF file in a RTB control using, for example: RTextBox1.SelFontName = cmbFonts.Text I have a RTF file -created with Word- displayed in a...
131
by: Peter Foti | last post by:
Simple question... which is better to use for defining font sizes and why? px and em seem to be the leading candidates. I know what the general answer is going to be, but I'm hoping to ultimately...
55
by: Haines Brown | last post by:
I've been setting font-size 1em; as the default in my style sheets. Until now, that seemed to be ok. But now I'm beginning to wonder. My aim is to have an easily readable, but not overly large...
7
by: Fabian Neumann | last post by:
Hi! I got a problem with font-family inheritance. Let's say I have CSS definitions like: p { font:normal 10pt Verdana; } strong { font:normal 14pt inherit;
6
by: Matt Adams | last post by:
I want define for a couple of words inside a longer text with different font specifications. I declared it like: ....text before.... <FONT class=aaa> these text should get other attributes...
4
by: Larry | last post by:
Although there are font attribute properties for the items in a ListView component, the complier tells me that they are read-only. Is there any way to get access and change the font poperties of...
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...
0
by: nitehawk416 | last post by:
I want to change the font of my rich text box to a font I downloaded. In the properties the font isn't there, so I tried changing it through the code with this variable declaration Font MUDFONT =...
6
by: andrew.ames | last post by:
Hi I have a pretty basic windows application created in Visual Studio 2005 and VB.NET. I set my Form's font to Arial 8.25pt, so when i added a label and a button they automatically have a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.