在richtextbox中更改所选文本的字体和颜色 [英] Changing font and colour of selected text in richtextbox
本文介绍了在richtextbox中更改所选文本的字体和颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好
您能否解释一下如何在RichTextBox中更改所选文本的字体和颜色?我找了很久,没有找到任何解决方案。只有如何更改整个TextBox的字体,这不是我想要的。如果我可以用新字体将文本保存到文件中,那将是理想的选择:
感谢您提供任何帮助
编辑:我做了一些实验
Hello
Can you please explain me how to change font and colour of selected text in RichTextBox? I was searching for long time and didn't find any solution. Only how to change font of entire TextBox and that's not what I want. If I could save the text to file with a new font it would be ideal :)
Thanks for any kind of help
I've done some experimenting
FontDialog fd1 = new FontDialog();
private void edit_Click(object sender, EventArgs e)
{
fd1.Font = textbox.SelectionFont;
if(fd1.ShowDialog() != DialogResult.Cancel)
{
textbox.Font = fd1.Font;
}
}
但看起来它用默认字体
but it looks like it saves it with the default font
推荐答案
您需要使用属性SelectionStart
和SelectionLength
选择文档的某些部分。然后,使用SelectionColor
,SelectionBackColor
之类的属性等。
请参阅:
http: //msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.aspx [ ^ ]。
-SA
You need to select some part of document using propertiesSelectionStart
andSelectionLength
. Then, use the properties likeSelectionColor
,SelectionBackColor
and the like.
Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.aspx[^].
—SA
这应该有帮助 [ ^ ]
chutie jesi site bana rakhi he lodo kuchh to milta ni he bhenchod
chutie jesi site bana rakhi he lodo kuchh to milta ni he bhenchod
这篇关于在richtextbox中更改所选文本的字体和颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文