如何在C#中的richtextbox中更改多种大小的字体? [英] How to change the font of multiple sizes in richtextbox in C#?
问题描述
我有一个富文本框,我想让它像写字板一样工作.我的问题是,例如,如果我使用 Calibri 字体输入123",然后使用 Arial 字体输入456"并且我想更改 2345 的大小,它不会让我这样做,因为他们有两个不同的字体类型.这就是我遇到问题的地方:
I have a richtextbox and I would like to make it work like WordPad. My problem is that, for example, if I type "123" using the Calibri font, and then "456" using the Arial font and I want to change the size of 2345 it won't let me to do it because they have two different font types. This is where I have the problem:
private void combo_sizes_TextChanged(object sender, EventArgs e)
{
if (rtb.SelectionFont == null)
{
rtb.SelectionFont = new Font(combo_fonts.Text, Convert.ToInt16(combo_sizes.Text));
}
rtb.SelectionFont = new Font(rtb.SelectionFont.FontFamily, Convert.ToInt16(combo_sizes.Text));
}
我知道当 rtb 中的选定文本包含多种字体时,SelectionFont 等于 null,因此在这种情况下,我已使其从两个组合框中获取选定文本的大小和字体,但我想更改大小而不会丢失其原始字体.有解决办法吗?
I know tha when the selected text in the rtb contains multiple fonts the SelectionFont equals to null, so in that case I have made it to get the selected text's size and font from two comboboxes, but I would like to change the size without losing its original font. Is there a solution?
谢谢
推荐答案
将您的 selected text
分解为 char
s.获取每个 char
的字体,并更改其大小.
Break your selected text
into char
s. Get each char
's Font, and change its size.
这篇关于如何在C#中的richtextbox中更改多种大小的字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!