Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have a button which has this code:
C#
fontsize = richTextBox1.Font.Size;
fontsize++;
richTextBox1.SelectionFont = new Font(richTextBox1.Font.Name, fontsize, richTextBox1.Font.Style, richTextBox1.Font.Unit);

The fontsize is a float by the way:
C#
static float fontsize = 9F; // declared at the start of program

Basically it sets the rich text box selected font 1 size bigger. But it doesn't work with SelectionFont.
It works fine with richTextBox1.Font = new Font .... This will just keep going up 1 every time but with SelectionFont it stops at 10 and won't go higher. And if I use another button to lower the SelectionFont size it won't go below 8 and it skips out 9.

What am I doing wrong with SelectionFont to make it like this? I just want the fontsize to go up and down, much like that of the buttons in MS Word.
Help please =)
Posted
Updated 13-Jan-12 5:25am
v3

You are using the wrong value to create the new font, you should be using the SelectionFont.Size like this:
C#
fontsize = richTextBox1.SelectionFont.Size + 1;
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-Jan-12 17:53pm    
This is a catch, my 5.
--SA
manognya kota 14-Jan-12 4:01am    
Good one. my 5.
It's something you're doing. There's no problem with the different point sizes. I just wired up an RTB and a NumericUpDown control and the following code worked just fine:
Font oldFont = RTB.SelectionFont;
Font newSize = new Font(oldFont.FontFamily.Name, FontSizeUD.Value, oldFont.Style);
RTB.SelectionFont = newSize;
 
Share this answer
 
All the comments are perfect
but,
For Temporary purpose u can use ctrl+ScrollUP OR Down to Min OR Max Font
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900