查找就不说了,richtextbox定位参考:http://www.syncfusion.com/faq/windowsforms/faq_c89c.aspx#q890q,插入带颜色的文字的方案有两种:
方案一,利用winform中richtextbox的selectioncolor方法给选中的文字设置颜色来做,示例代码:
private void FormMain_Load(object sender, EventArgs e)
{
rtxtRecord.Text = "abc";
changecolor("abc", Color.Red);
}
private void changecolor(string searchString, System.Drawing.Color color)
{
int index;
index = rtxtRecord.Text.IndexOf(searchString);
while (index != -1)
{
rtxtRecord.Select(index, searchString.Length);
rtxtRecord.SelectionColor = color;
index = rtxtRecord.Text.IndexOf(searchString, index + 1);
}
}
rtxtRecord是richtextbox控件ID
方案二是直接用rtf格式字符串写,示例:
private void FormMain_Load(object sender, EventArgs e)
{
rtxtRecord.Rtf = @"{\rtf1{\colortbl;\red255\green0\blue0;}\cf1abcd}";
}
将会出现红色的abcd