Click here to Skip to main content
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 6:12am
Edited 13-Jan-12 6:25am
Mehdi Gholam258.5K
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 Mika Wendelius 261
1 Abhinav S 155
2 Peter Leow 140
3 Sergey Alexandrovich Kryukov 125
4 Kornfeld Eliyahu Peter 115
0 Sergey Alexandrovich Kryukov 8,593
1 OriginalGriff 6,536
2 Peter Leow 3,727
3 Zoltán Zörgő 3,456
4 Richard MacCutchan 2,417

Advertise | Privacy | Mobile
Web01 | 2.8.150123.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