怎样将文字变成红色或自定义颜色。 string aa="abcdefghijk"; //一个字符串string bb="efg"; //要改变颜色的字符串richTextBox1.Text="abcd (红色开始)efg(红色结束)hijk"; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 richTextBox1.Select(Start, length);richTextBox1.SelectionColor = Color.Red; richTextBox是支持html的代码的,用font标签加上color就可以了。 用replace给替换成efg加上<font color='red'>efg</font> Font f=new Font("Verdana", 8F, FontStyle.Italic, GraphicsUnit.Point);string str="";if (richTextBox1.Find(str)>0){int pos=richTextBox1.Find(str);richTextBox1.SelectionStart=pos;richTextBox1.SelectionLength=str.Length; richTextBox1.SelectionFont=f;richTextBox1.SelectionColor=Color.Red;} 可以用JS的代码来写 用声明变量的方法来写 或者用hyperlink来写 在属性里面的"style"来改 Font f=new Font("Verdana", 8F, FontStyle.Italic, GraphicsUnit.Point);string str="";if (richTextBox1.Find(str)>0){int pos=richTextBox1.Find(str);richTextBox1.SelectionStart=pos;richTextBox1.SelectionLength=str.Length; richTextBox1.SelectionFont=f;richTextBox1.SelectionColor=Color.Red;} //设置第4个字符开始长度为2的字符串颜色为红色 this.richTextBox1.Select(3, 2); this.richTextBox1.SelectionColor = System.Drawing.Color.Red; //设置第6个字符开始长度为3的字符串颜色为蓝色 this.richTextBox1.Select(5, 3); this.richTextBox1.SelectionColor = System.Drawing.Color.Blue; HttpWebRequest第一次请求为什么很慢 请教一个C#字节流转换的问题 很难。高手帮忙!通过url抓取网页内容保存到本地服务器,供客户访问,且同步更新 急,实在搞不懂连接数据库哪里出错了,哪位老大帮忙看看,第一次学会给分 两个DATATABLE的合并问题 C#里面怎么写一个全局函数和建一个全局变量,就是在整个工程内都有效的那种 时间格式问题 MFC中最接近C#的ArrayList类的是哪个类? 网络序列化问题 C#查出1到8000中没有的数据 动态添加控件后出现的类型转换(请教) c# 使用FileStream读取大于计算机内存文件的解决办法
richTextBox1.SelectionColor = Color.Red;
string str="";
if (richTextBox1.Find(str)>0)
{
int pos=richTextBox1.Find(str);
richTextBox1.SelectionStart=pos;
richTextBox1.SelectionLength=str.Length;
richTextBox1.SelectionFont=f;
richTextBox1.SelectionColor=Color.Red;
}
或者用hyperlink来写 在属性里面的"style"来改
string str="";
if (richTextBox1.Find(str)>0)
{
int pos=richTextBox1.Find(str);
richTextBox1.SelectionStart=pos;
richTextBox1.SelectionLength=str.Length;
richTextBox1.SelectionFont=f;
richTextBox1.SelectionColor=Color.Red;
}
//设置第4个字符开始长度为2的字符串颜色为红色
this.richTextBox1.Select(3, 2);
this.richTextBox1.SelectionColor = System.Drawing.Color.Red;
//设置第6个字符开始长度为3的字符串颜色为蓝色
this.richTextBox1.Select(5, 3);
this.richTextBox1.SelectionColor = System.Drawing.Color.Blue;