Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/12/2009, 08:35
chascos69
 
Fecha de Ingreso: enero-2008
Mensajes: 229
Antigüedad: 17 años, 3 meses
Puntos: 0
Conservar formato richtextbox

Hola

He hecho un experimento sencillo

Tengo un control richtextbox que le añado la string a con color azul mediante un boton y la b con color rojo mediante otro boton...

1 - Inserto a azul y ok
2 - Inserto la b roja y ok
3 - Inserto b roja DE NUEVO y ... que paso? La segunda b es azul?

La secuencia debería ser azul, rojo, rojo y no azul, azul, rojo...

Es decir, si voy pulsando b roja, me lo deja en rojo pero el anterior caracter me lo cambia a azul... ???

A ver si alguien sabe pq....

Codigo:
Private Sub AAzul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAAzul.Click
EscribirTextoEnTextoAcumulado(Color.Blue, "a")
End Sub

......

Private Sub BRojo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnBRojo.Click
EscribirTextoEnTextoAcumulado(Color.Red, "b")
End Sub

......

Private Sub EscribirTextoEnTextoAcumulado(ByVal ColorFuente As Color, _
ByVal TextoQueSeEscribe As String)
Dim AntiguaPosicion As Integer
With RichTextBox1
AntiguaPosicion = Len(.Text)
.Text &= TextoQueSeEscribe
.SelectionStart = .Find(TextoQueSeEscribe.Trim, AntiguaPosicion, RichTextBoxFinds.None)
.SelectionColor = ColorFuente
.SelectionStart = Len(.Text)
.SelectionLength = 0
End With
End Sub