Ver Mensaje Individual
  #2 (permalink)  
Antiguo 08/02/2010, 09:01
Avatar de Carlojas
Carlojas
 
Fecha de Ingreso: junio-2007
Ubicación: Shikasta
Mensajes: 1.272
Antigüedad: 16 años, 10 meses
Puntos: 49
Respuesta: Buscar y colorear frases en un RichTextBox

Buenos dias compañeros despues de buscar encontre esta forma para hacer lo que necesitaba:
Código vb:
Ver original
  1. Imports System.Text.RegularExpressions
  2.  
  3.     Private Sub Buscar_Coincidencia( _
  4.       ByVal pattern As String, _
  5.       ByVal RichTextBox As RichTextBox, _
  6.       ByVal cColor As Color, _
  7.      ByVal BackColor As Color)
  8.  
  9.  
  10.         Dim Resultados As MatchCollection
  11.         Dim Palabra As Match
  12.  
  13.         Try
  14.             Dim obj_Expresion As New Regex(pattern.ToString, RegexOptions.IgnoreCase)
  15.             Resultados = obj_Expresion.Matches(RichTextBox.Text)
  16.  
  17.             With RichTextBox
  18.                 .SelectAll()
  19.                 .SelectionColor = Color.Black
  20.             End With
  21.  
  22.             For Each Palabra In Resultados
  23.                 With RichTextBox
  24.                     .SelectionStart = Palabra.Index
  25.                     .SelectionLength = Palabra.Length
  26.                     .SelectionColor = cColor
  27.                     .SelectionBackColor = BackColor
  28.                     .SelectionFont = New Font(FontStyle.Bold, 11, FontStyle.Bold, GraphicsUnit.Pixel)
  29.                     Debug.Print(Palabra.Value)
  30.                 End With
  31.             Next Palabra
  32.         Catch ex As Exception
  33.             MsgBox(ex.Message.ToString)
  34.         End Try
  35.     End Sub
  36.  
  37. 'Para utilizarlo
  38. Call Buscar_Coincidencia(resultado, Me.log_read, Color.Blue, Color.Yellow
)


Saludos.
__________________
"SELECT * FROM Mujeres WHERE situacion NOT IN ('CASADAS','CON HIJOS','ATORMENTADAS','CUASI-ENNOVIADAS') AND personalidad <> 'INTENSA'"