Solved

RTF Question

Posted on 2003-11-04
1
195 Views
Last Modified: 2010-04-16
I have a RichTextBox. When the user types in a certain word such as "hello" I want the font color of that word to chance to another color like blue. This is like syntax highlighting in Visual Studio .Net and other development enviroments. Ive tried to do this but cannot find an answer. Please help me.
0
Comment
Question by:GoRgOn
1 Comment
 
LVL 1

Accepted Solution

by:
rashmitodkar earned 50 total points
ID: 9700098
hi try with the following code

private void RTB_TextChanged(object sender, System.EventArgs e)
            {
                  for (int i=0;i<RTB.Text.Length;i++)
                  {
                        if (RTB.Text.IndexOf("hello",i)>=0)
                        {
                              RTB.Select(RTB.Text.IndexOf("hello",i),5);    
                              RTB.SelectionColor =Color.Blue;    
                              RTB.Select(RTB.Text.Length,0);
                              RTB.SelectionColor =Color.Black ;  
                              i=i+5;
                        }
                  }
                  
                  
            }
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question