c# RichTextBox用法——设置指定字符串的颜色
2017-08-16 17:57
323 查看
本文转载连接: http://blog.csdn.net/crazytaliban/article/details/52002657
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace RichTextBoxUse
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ArrayList list = getIndexArray(richTextBox1.Text, "str1");
for (int i = 0; i < list.Count; i++)
{
int index = (int)list[i];
richTextBox1.Select(index, "str1".Length);
richTextBox1.SelectionColor = Color.Red;
}
}
private ArrayList getIndexArray(String inputStr, String findStr)
{
ArrayList list = new ArrayList();
int start = 0;
while (start < inputStr.Length)
{
int index = inputStr.IndexOf(findStr, start);
if (index >= 0)
{
list.Add(index);
start = index + findStr.Length;
}
else
{
break;
}
}
return list;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace RichTextBoxUse
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ArrayList list = getIndexArray(richTextBox1.Text, "str1");
for (int i = 0; i < list.Count; i++)
{
int index = (int)list[i];
richTextBox1.Select(index, "str1".Length);
richTextBox1.SelectionColor = Color.Red;
}
}
private ArrayList getIndexArray(String inputStr, String findStr)
{
ArrayList list = new ArrayList();
int start = 0;
while (start < inputStr.Length)
{
int index = inputStr.IndexOf(findStr, start);
if (index >= 0)
{
list.Add(index);
start = index + findStr.Length;
}
else
{
break;
}
}
return list;
}
}
}
相关文章推荐
- RichTextBox用法——设置指定字符串的颜色
- RichEditControl用法——设置指定字符串的字体颜色
- 设置标签中字符串的子串(指定位置)的颜色
- iOS设置字符串指定位置的颜色和字体
- android textview字符串指定分段设置字体颜色
- iOS开发:字符串设置指定内容的文字颜色、文字大小、文字字体类型
- 关于TextView中,设置指定部分文字改变颜色,和指定部分文字点击事件
- 记录一次查找字符串中多个相同字符,并设置指定大小显示
- 字符串的截取-设置字符串中某些文字的颜色
- dateNavigator指定日期设置背景颜色
- POI使用cell.getCellStyle()设置指定单元格颜色,但是其它没有指定的单元格也会变色
- c#怎么设置一个字符串中某个字符的颜色
- TextView中设置指定位置字符颜色
- 「彩」fontcolor() //使用指定的颜色来显示字符串 20140813 ①文本处理
- 字符串部分字符设置颜色
- iOS开发 字符串中截取关键字并给他设置颜色
- echo命令_Linux echo 命令用法详解:输出指定的字符串或者变量
- Android编程设置TextView颜色setTextColor用法实例
- 潜移默化学会WPF(技巧篇)--关于后台如何设置字符串的颜色的方法
- [QualityCenter]设置工作流脚本-根据某字段是否包含指定字符串来判断其他字段的选值