elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
29 Mayo 2012, 03:11  


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)

+  Foro de elhacker.net
|-+  Programación
| |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo, raul338)
| | |-+  Colores en RichTextBox [Solucionado]
0 Usuarios y 2 Visitantes están viendo este tema.
Páginas: 1 [2] Ir Abajo Respuesta Imprimir
Autor Tema: Colores en RichTextBox [Solucionado]  (Leído 1,895 veces)
Tenient101

Desconectado Desconectado

Mensajes: 127


Ver Perfil
Re: Colores en RichTextBox
« Respuesta #15 en: 19 Marzo 2011, 19:28 »

Código
Public Function ChangeColor(RT As RichTextBox, StrStart As String, StrEnd As String, Color As Long)
Dim Text        As String
Dim N           As Long
 
       Text = RT.Text
       N = InStr(Text, StrStart)
       Do While CBool(N)
           Mid(Text, N, Len(StrStart)) = String(Len(StrStart), "?")
           RT.SelStart = N + Len(StrStart)
           N = InStr(Text, StrEnd)
           If CBool(N) Then
               Mid(Text, N, Len(StrEnd)) = String(Len(StrEnd), "?")
               RT.SelLength = N - RT.SelStart - 1
               RT.SelColor = Color
               RT.SelStart = 0
           End If
       N = InStr(Text, StrStart)
       DoEvents
       Loop
       If CBool(RT.SelStart) Then
           RT.SelLength = Len(RT.Text) - RT.SelStart
           RT.SelColor = color
       End If
 
End Function
 
ChangeColor RT, ":", vbNewLine, vbBlue
 
:P, lo hize a prisas XD


« Última modificación: 19 Marzo 2011, 19:30 por Tenient101 » En línea
DarkMatrix

Desconectado Desconectado

Mensajes: 125


Nuestro Limite es la Imaginacion


Ver Perfil WWW
Re: Colores en RichTextBox
« Respuesta #16 en: 19 Marzo 2011, 21:15 »

Yo lo hago asi

En un Modulo:

Código
Option Explicit
 
Enum eTextColor
 
   Black = 0
   Blue = 1
   Green = 2
   Cyan = 3
   Red = 4
   Magenta = 5
   Brown = 6
   Grey = 7
   DarkGrey = 8
   BrightBlue = 9
   BrightGreen = 10
   BrightCyan = 11
   BrightRed = 12
   Pink = 13
   Yellow = 14
   white = 15
 
End Enum
 
Public Sub AddText(oRichTextBox As Object, ByVal Msg As String, ByVal Color As eTextColor, Optional NewLine As Boolean = True, Optional CustomColor As Long = -1)
 
   Dim s As String
   Dim c As Long
 
   If NewLine = True Then
 
       s = Msg & vbNewLine
 
   Else
 
       s = Msg
 
   End If
 
   c = oRichTextBox.SelStart
   oRichTextBox.SelStart = Len(oRichTextBox.Text)
 
   If CustomColor <> -1 Then
 
       oRichTextBox.SelColor = CustomColor
 
   Else
 
       oRichTextBox.SelColor = QBColor(Color)
 
   End If
 
   oRichTextBox.SelText = s
   oRichTextBox.SelStart = Len(oRichTextBox.Text) - 1
 
End Sub

En Tu Codigo lo llamarias asi

Código
If Mid(Datos, 1, 3) = "MSG" Then 'Cuando recibo es MSGmensaje

   Mensaje = Split(Mid(Datos, 4, Len(Datos)), ":")
 
   Call AddText(Text1.Text, Mensaje(0) & ": ", vbBlack, False)
   Call AddText(Text1.Text, Mensaje(1), vbBlue, True)
 
End If


En línea

Todo aquello que no se puede hacer, es lo que no intentamos hacer.
Projecto Ani-Dimension Digital Duel Masters (Juego de cartas masivo multijugador online hecho en Visual Basic 6.0)

Desing by DarkMatrix
Stelio Kontos

Desconectado Desconectado

Mensajes: 17


Ver Perfil
Re: Colores en RichTextBox
« Respuesta #17 en: 23 Marzo 2011, 15:11 »

Usé y modifiqué a mi gusto el módulo de DarkMatrix y funciona perfecto.
Solucionado, muchas gracias.
En línea
Páginas: 1 [2] Ir Arriba Respuesta Imprimir 

Ir a:  

Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines