在RichTextBox中更改分号的颜色 [英] Change Color of a semicolon in RichTextBox
本文介绍了在RichTextBox中更改分号的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
i我的Windows窗体中有一个RichTextbox,如果用户输入Semicolon(;)然后我需要让它变粗并将颜色改为红色
敌人例如:
Hi All,
i am having a RichTextbox in my windows form if the user will enter Semicolon(;) then i need to make it Bold and change color to Red
foe eg:
insert into TableName values (1,'UserName1');
insert into TableName values (2,'UserName2');
insert into TableName values (3,'UserName3');
insert into TableName values (4,'UserName4');
i在textchange事件上试过这个
i have tried this on textchange event
Dim str As String = ";"
If txtScript.Find(str) > 0 Then
Dim pos As Integer = txtScript.Find(str)
txtScript.SelectionStart = pos
txtScript.SelectionLength = str.Length
txtScript.SelectionColor = Color.Red
End If
但是在第一个分号之后它改变了文本框中整个文本的颜色我只需要更改分号
最好的问候..
but after the first semicolon it is changing the color of whole text in textbox i need to change only of semicolon
Best Regards..
推荐答案
很容易做到 -
Quite easy to do -
string str=@"'";
if (richTextBox1.Find(str)>0)
{
int pos=richTextBox1.Find(str);
richTextBox1.SelectionStart=pos;
richTextBox1.SelectionLength=str.Length;
richTextBox1.SelectionColor=Color.Green; //Your color here
}
上面的代码可以修改为更改任何文本的颜色(使用 str
常量)。
这篇关于在RichTextBox中更改分号的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文