richtextbox con linea de cada color
Publicado por sergio (7 intervenciones) el 26/03/2009 23:26:30
Quiero hacer un richtextbox con una linea de cada color. Tengo este código:
Public Class Form1
Dim UltimaPosicion As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With RichTextBox1
.Text &= "AAAA" & vbNewLine
.SelectionStart = UltimaPosicion
.SelectionLength = .TextLength
.SelectionFont = New Font(.SelectionFont.FontFamily, .SelectionFont.Size, FontStyle.Regular)
.SelectionColor = Color.Red
'.SelectionStart = .SelectionStart + .SelectionLength
.Refresh()
UltimaPosicion = .SelectionStart + .SelectionLength
End With
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
With RichTextBox1
.Text &= "BBBB" & vbNewLine
.SelectionStart = UltimaPosicion
.SelectionLength = .TextLength
.SelectionFont = New Font(.SelectionFont.FontFamily, .SelectionFont.Size, FontStyle.Regular)
.SelectionColor = Color.Blue
'.SelectionStart = .SelectionStart + .SelectionLength
.Refresh()
UltimaPosicion = .SelectionStart + .SelectionLength
End With
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
UltimaPosicion = 0
RichTextBox1.Text = String.Empty
End Sub
End Class
Pero al tercer intento no hace lo correcto... pone las tres lineas en el color que has empezado. Alguien sabe pq.?
Asias
Public Class Form1
Dim UltimaPosicion As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With RichTextBox1
.Text &= "AAAA" & vbNewLine
.SelectionStart = UltimaPosicion
.SelectionLength = .TextLength
.SelectionFont = New Font(.SelectionFont.FontFamily, .SelectionFont.Size, FontStyle.Regular)
.SelectionColor = Color.Red
'.SelectionStart = .SelectionStart + .SelectionLength
.Refresh()
UltimaPosicion = .SelectionStart + .SelectionLength
End With
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
With RichTextBox1
.Text &= "BBBB" & vbNewLine
.SelectionStart = UltimaPosicion
.SelectionLength = .TextLength
.SelectionFont = New Font(.SelectionFont.FontFamily, .SelectionFont.Size, FontStyle.Regular)
.SelectionColor = Color.Blue
'.SelectionStart = .SelectionStart + .SelectionLength
.Refresh()
UltimaPosicion = .SelectionStart + .SelectionLength
End With
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
UltimaPosicion = 0
RichTextBox1.Text = String.Empty
End Sub
End Class
Pero al tercer intento no hace lo correcto... pone las tres lineas en el color que has empezado. Alguien sabe pq.?
Asias
Valora esta pregunta


0