Click here to Skip to main content
Rate this: bad
good
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;
            fontsize++;
            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 Gholam253.2K
v3
Rate this: bad
good
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;
  Permalink  
Comments
SAKryukov at 13-Jan-12 17:53pm
   
This is a catch, my 5.
--SA
manognya kota at 14-Jan-12 4:01am
   
Good one. my 5.
Rate this: bad
good
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;
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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

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

  Print Answers RSS
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 14 Jan 2012
Copyright © CodeProject, 1999-2014
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