How to preserve font properties while changing some other properties.

How to preserve font properties while changing some other properties.

Post by Sakharam P » Tue, 05 Oct 2004 14:46:18


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
 
 
 

How to preserve font properties while changing some other properties.

Post by Sakharam P » Tue, 05 Oct 2004 15:05:02


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

 
 
 

How to preserve font properties while changing some other properties.

Post by Cor Ligthe » Tue, 05 Oct 2004 16:34:23

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
 
 
 

How to preserve font properties while changing some other properties.

Post by Sakharam P » Wed, 06 Oct 2004 21:50:35

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
 
 
 

How to preserve font properties while changing some other properties.

Post by Sakharam P » Thu, 07 Oct 2004 14:22:59

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