Richtextbox中的字体大小不会超过10 [英] Font size won't go above 10 in richtextbox

查看:124
本文介绍了Richtextbox中的字体大小不会超过10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下代码的按钮:

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);


顺便说一下,fontsize是一个浮点数:


The fontsize is a float by the way:

static float fontsize = 9F; // declared at the start of program


基本上,它会将富文本框选择的字体设置为1大.但这不适用于SelectionFont.
它可以与richTextBox1.Font = new Font ...一起很好地工作.每次将只保持1上升,但是使用SelectionFont时,它将停止在10处并且不会上升.如果我使用另一个按钮减小SelectionFont的大小,它将不会低于8,并且会跳过9.

我使用SelectionFont怎么做才能使它像这样?我只希望fontsize可以上下移动,就像MS Word中的按钮一样.
请帮忙=)


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 =)

推荐答案

您使用错误的值来创建新字体,您应该使用SelectionFont.Size像这样:
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;


这是您正在做的事情.不同的点大小没有问题.我只连接了一个RTB和一个NumericUpDown控件,下面的代码就可以了:
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;


所有评论都是完美的
但是,
出于临时目的,您可以使用ctrl + ScrollUP或Down到Min或Max Font
All the comments are perfect
but,
For Temporary purpose u can use ctrl+ScrollUP OR Down to Min OR Max Font


这篇关于Richtextbox中的字体大小不会超过10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆