Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
SQL
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 have tried this on textchange event
VB
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..
Posted
Updated 4-Feb-14 0:02am
v4
Comments
Kornfeld Eliyahu Peter 4-Feb-14 5:45am    
Have you done anything so far? Show some effort (code or searching?)! As is it ain't a question...
Basmeh Awad 4-Feb-14 6:00am    
yes i tried..updated the question

1 solution

Quite easy to do -

C#
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
}


The code above can be modified to change the color for any text (use the str constant for that).
 
Share this answer
 
Comments
Basmeh Awad 4-Feb-14 5:57am    
thanks.. i have tried this code before but its not actually what i need because
if i am entering this text in textbox
insert into TableName values (1,'UserName1');
insert into TableName values (2,'UserName2');
insert into TableName values (3,'UserName3');
insert into TableName values (4,'UserName4');

after the first semicolon it is changing the color of every text in textbox i need to change only of semicolon
Abhinav S 4-Feb-14 6:03am    
Ensure pos value is correct.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900