本文介绍了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 =)

推荐答案

fontsize = richTextBox1.SelectionFont.Size + 1;


Font oldFont = RTB.SelectionFont;
Font newSize = new Font(oldFont.FontFamily.Name, FontSizeUD.Value, oldFont.Style);
RTB.SelectionFont = newSize;



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

09-19 00:55