更改RichTextBox中的默认颜色文本 [英] Change Default Color Text in RichTextBox

查看:94
本文介绍了更改RichTextBox中的默认颜色文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我有richtextbox.选择特定文本时,默认蓝色将显示在所选文本上.我想将蓝色更改为其他颜色.

我该如何更改?

In my project I have richtextbox. On selecting particular text default blue color appears on the selected text. I want to change that blue color to some other color.

How can i change?

推荐答案

注意:假设您正在谈论设置所选文本的背景色,我选择回答此问题.设置文本前景色,只需在下面的示例中将"SelectionColor"替换为"SelectionBackColor"即可.

假设一个名为"richTextBox1"的WinForms RichTextBox控件:您可以在运行时修改任何当前选定文本的背景颜色,如下所示:
Note: I''ve chosen to answer this question assuming you are talking about setting the background color of selected text: to set the text foreground color, just substitute ''SelectionColor'' in the examples below for ''SelectionBackColor.''

Assuming a WinForms RichTextBox control named ''richTextBox1: you can modify, at run-time, the background color of any currently selected text like this:
richTextBox1.SelectionBackColor = Color.Gold;

RichTextBox"SelectionBackColor"是同时包含"set和"的属性get方法:这样您就可以分析当前背景色是什么颜色,并根据需要根据分析结果进行各种操作.

而且,当然,您可以通过设置自己的选择来以编程方式操纵RTF文本的背景色:

RichTextBox ''SelectionBackColor'' is a Property with both ''set and ''get methods: so you can analyze what color the current background color is, and do various things based on the result of your analysis, if you wish.

And, of course you can manipulate the background color of the RTF text programmatically by setting your own selection:

richTextBox1.Text = @"line1
line2
line3
line4";

richTextBox1.SelectionStart = 0;
richTextBox1.SelectionLength = 5;
richTextBox1.SelectionBackColor = Color.LightSkyBlue;

如果您在RichTextBox中选择的文本包含多种颜色会怎样?在这种情况下,我可以建议您探索一下"SelectionBackColor"返回的值是什么.

What happens if your selected text in the RichTextBox contains more than one color ? May I suggest you explore, in that case, what the value returned by ''SelectionBackColor'' will be.


这篇关于更改RichTextBox中的默认颜色文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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