By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,579 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,579 IT Pros & Developers. It's quick & easy.

How to preserve font properties while changing some other properties.

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a

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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.