Ver Mensaje Individual
  #9 (permalink)  
Antiguo 10/12/2009, 06:49
Avatar de pkj
pkj
 
Fecha de Ingreso: julio-2006
Ubicación: Órbita sincrónica
Mensajes: 899
Antigüedad: 17 años, 9 meses
Puntos: 29
Respuesta: Un Reto: Mensaje de texto rotativo

A ver que te parece esto.
Tiene el problema del parpadeo, sobre todo porque la sub que colorea el texto es bastante lenta, pero el resultado de momento es el buscado.
Me he limitado a 5 colores, pero verás que es facil añadir mas.

RT1 es el RichTextBox

Código :
Ver original
  1. Option Explicit
  2. Dim Colores(5) As ColorConstants
  3.  
  4. Private Sub Form_Load()
  5.   Colores(0) = vbBlack
  6.   Colores(1) = vbBlue
  7.   Colores(2) = vbRed
  8.   Colores(3) = vbGreen
  9.   Colores(4) = vbMagenta
  10.   Colores(5) = vbYellow
  11.   Me.Show
  12. End Sub
  13.  
  14. Private Sub RT1_Change()
  15.   Dim Pos As Long
  16.   With RT1
  17.     .Visible = False
  18.     Pos = .SelStart
  19.     CambiaColores RT1
  20.     .SelStart = Pos
  21.     .Visible = True
  22.     .SetFocus
  23.   End With
  24.  End Sub
  25.  
  26. Sub CambiaColores(RTB As RichTextBox)
  27.   Dim F As Long
  28.   Dim Contador As Long
  29.   With RTB
  30.   For F = 1 To Len(.Text)
  31.     If Mid$(.Text, F, 1) = "{" Then
  32.       Contador = Contador + 1
  33.       If Contador > 5 Then Contador = 5
  34.       .SelStart = F - 1
  35.       .SelLength = 1
  36.       .SelColor = Colores(Contador)
  37.     ElseIf Mid$(.Text, F, 1) = "}" Then
  38.       .SelStart = F - 1
  39.       .SelLength = 1
  40.       .SelColor = Colores(Contador)
  41.       Contador = Contador - 1
  42.       If Contador < 0 Then Contador = 0
  43.     Else
  44.       .SelStart = F - 1
  45.       .SelLength = 1
  46.       .SelColor = Colores(Contador)
  47.     End If
  48.   Next F
  49.   End With
  50. End Sub

Saludos
__________________
No hay preguntas tontas, solo gente estup..., ¡No!, ¿como era? No hay gente que pregunte a tontos... ¡Nooo!... ¡Vaya cabeza!