Click here to Skip to main content
11,707,254 members (55,467 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# buttons size font
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
Edited 13-Jan-12 5:25am
Mehdi Gholam285.2K
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 at 13-Jan-12 17:53pm
This is a catch, my 5.
manognya kota at 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
0 Sergey Alexandrovich Kryukov 145
1 OriginalGriff 141
2 chainerlt 110
3 Mika Wendelius 80
4 Maciej Los 80
0 OriginalGriff 9,178
1 Sergey Alexandrovich Kryukov 8,562
2 CPallini 5,189
3 Maciej Los 4,806
4 Mika Wendelius 3,706

Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 14 Jan 2012
Copyright © CodeProject, 1999-2015
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