Click here to Skip to main content
11,636,260 members (82,459 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 Gholam282.6K
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 333
1 OriginalGriff 283
2 Sergey Alexandrovich Kryukov 255
3 Suvendu Shekhar Giri 225
4 Mika Wendelius 204
0 OriginalGriff 8,941
1 Sergey Alexandrovich Kryukov 8,459
2 Mika Wendelius 6,849
3 F-ES Sitecore 2,364
4 Suvendu Shekhar Giri 2,320

Advertise | Privacy | Mobile
Web02 | 2.8.150728.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