mercredi 1 avril 2015

Readonly richtextbox changing color of keyword C#

I have a rich text box that i am using to display an example of the Hello World program and want the keywords such as 'using' 'namespace' 'class' 'static' 'void' 'string' to display blue.


I have got 'using' to display blue but only when the user starts to type or types 'using' I want the richtextbox to be read only not allowing an user input into it


Here is my code:



private void rtb_TextChanged(object sender, EventArgs e)
{
string find = "using";
if (rtb.Text.Contains(find))
{
var matchString = Regex.Escape(find);
foreach (Match match in Regex.Matches(rtb.Text, matchString))
{
rtb.Select(match.Index, find.Length);
rtb.SelectionColor = Color.Blue;
rtb.Select(rtb.TextLength, 0);
rtb.SelectionColor = rtb.ForeColor;
};
}
}


I am having trouble figuring out how to do it for readonly rtb. How could i edit my code to display the blue text on initialize in a readonly rtb


Thanks for your help


Aucun commentaire:

Enregistrer un commentaire