如何使用多色彩的richtextbox [英] How to use multi color in richtextbox

查看:171
本文介绍了如何使用多色彩的richtextbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#Windows Forms和我的richtextbox,我要的颜色一些文字为红色,一些绿色和一些黑色的。

I using C# windows forms and I have richtextbox and I want to color some text in red, some in green and some in black.

怎么办呢?图片附后。

How to do so? Image attached.

推荐答案

System.Windows.Forms.RichTextBox 已得到类型的属性颜色名称 selectionColor设置它获取或设置当前选择或插入点的文字颜色。您可以使用此属性来标记你的的RichTextBox 具体领域与您指定的颜色。

System.Windows.Forms.RichTextBox has got a property of type Color of the name SelectionColor which gets or sets the text color of the current selection or insertion point. You can use this property to mark specific fields in your RichTextBox with the colors you specify.

示例

RichTextBox _RichTextBox = new RichTextBox(); //Initialize a new RichTextBox of name _RichTextBox
_RichTextBox.Select(0, 8); //Select text within 0 and 8
_RichTextBox.SelectionColor = Color.Red; //Set the selected text color to Red
_RichTextBox.Select(8, 16); //Select text within 8 and 16
_RichTextBox.SelectionColor = Color.Green; //Set the selected text color to Green
_RichTextBox.Select(0,0); //Select text within 0 and 0

请注意:您可以避开计算使用 RichTextBox.Find(字符串str)可以通过添加对象浏览器如果你想突出的的RichTextBox 中的文本给它的值

Notice that: You may avoid calculations by using RichTextBox.Find(string str) which can be added through Object Browser if you would like to highlight the text within the Lines in RichTextBox giving it's value

示例

RichTextBox _RichTextBox = new RichTextBox(); //Initialize a new RichTextBox of name _RichTextBox
_RichTextBox.Find("Account 12345, deposit 100$, balance 200$"); //Find the text provided
_RichTextBox.SelectionColor = Color.Green; //Set the selected text color to Green

谢谢,
我希望对您有所帮助:)

Thanks,
I hope you find this helpful :)

这篇关于如何使用多色彩的richtextbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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