Click here to Skip to main content
13,043,491 members (53,435 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have a button which has this code:
fontsize = richTextBox1.Font.Size;
richTextBox1.SelectionFont = new Font(richTextBox1.Font.Name, fontsize, richTextBox1.Font.Style, richTextBox1.Font.Unit);

The fontsize is a float by the way:
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 13-Jan-12 5:12am
Updated 13-Jan-12 5:25am
Mehdi Gholam339.3K
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You are using the wrong value to create the new font, you should be using the SelectionFont.Size like this:
fontsize = richTextBox1.SelectionFont.Size + 1;
SAKryukov 13-Jan-12 17:53pm
This is a catch, my 5.
manognya kota 14-Jan-12 4:01am
Good one. my 5.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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;
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

All the comments are perfect
For Temporary purpose u can use ctrl+ScrollUP OR Down to Min OR Max Font

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 14 Jan 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100