Ver Mensaje Individual
  #2 (permalink)  
Antiguo 10/09/2012, 09:23
Avatar de Aquaventus
Aquaventus
 
Fecha de Ingreso: junio-2010
Ubicación: Lima-Peru , En el alba de la naturaleza
Mensajes: 2.105
Antigüedad: 13 años, 10 meses
Puntos: 267
Respuesta: Colorear una palabra en richtextbox en C#

Hola gedard1!!!
1º Bienvenido al Foro!!.
2º Ya logré modificar y al parecer ya no cae en problemas, trata de analizar el código :

Código C:
Ver original
  1. public partial class Form1 : Form
  2.     {
  3.         string[] Reservadas = new string[] { "else", "if" };
  4.         int posicion = 0;
  5.  
  6.           public Form1()
  7.         {
  8.             InitializeComponent();
  9.             {
  10.             ejecucion();
  11.  
  12.             this.richTextBox1.SelectionStart = this.richTextBox1.Text.Length;
  13.  
  14.             this.richTextBox1.TextChanged += (ob, ev) =>
  15.                 {
  16.                     posicion = richTextBox1.SelectionStart;
  17.                     ejecucion();
  18.                 };
  19.  
  20.             }
  21.         }
  22.  
  23.         private void ejecucion()
  24.         {
  25.             this.richTextBox1.Select(0, richTextBox1.Text.Length);
  26.             this.richTextBox1.SelectionColor = Color.Black;
  27.             this.richTextBox1.Select(posicion, 0);
  28.  
  29.             string[] texto = richTextBox1.Text.Trim().Split(' ');
  30.             int inicio = 0;
  31.  
  32.             foreach (string x in texto)
  33.             {
  34.                 foreach (string y in Reservadas)
  35.                 {
  36.                     if (x.Length != 0)
  37.                     {
  38.                         if (x.Trim().Equals(y))
  39.                         {
  40.                             inicio = this.richTextBox1.Text.IndexOf(x, inicio);
  41.                             this.richTextBox1.Select(inicio, x.Length);
  42.                             richTextBox1.SelectionColor = Color.Red;
  43.                             this.richTextBox1.Select(posicion, 0);
  44.                             inicio = inicio + 1;
  45.                         }
  46.                     }
  47.                 }
  48.             }
  49.         }
  50.  
  51.     }
Saludos!.
__________________
Internet es tener todo el conocimiento global a tu disposición.
Desarrollo de Software - Ejemplos .Net

Última edición por Aquaventus; 10/09/2012 a las 14:06 Razón: Correjido completamente.