Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a richtextbox and what I want to be able to do is to format each line, so one line would be say italic and another line would be bold.

 

I have done the following code which changes the second line to bold, however if you click the button again to write some more text to the richtextbox the formatting of the previous text is lost:

 

   Private Sub btnClient_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClient.Click
       Dim line1 As String = "Client Says [" & Now().ToString & "]"
       Dim line2 As String = "[" & Now().ToString & "]" & " Simon - Hello how are you"

       Me.RichTextBox1.Text += line1 & vbNewLine
       textColour(line1, False)
       Me.RichTextBox1.Text += line2 & vbNewLine
       textColour(line2, True)

       Me.RichTextBox1.SelectionStart = Me.RichTextBox1.Text.Length

   End Sub

   Private Sub textColour(ByVal text As String, ByVal bold As Boolean)
       Dim newFont As Font
       RichTextBox1.SelectionStart = RichTextBox1.Find(text)

       If bold = True Then
           newFont = New Font(Me.cmbFont.Font, FontStyle.Bold)
       Else
           newFont = New Font(Me.cmbFont.Font, FontStyle.Regular)
       End If

       RichTextBox1.SelectionFont = newFont
   End Sub

 

I obviously need some help one keeping the format, basically I want to acheive the type of formating style that msn messenger has.

 

Thanks in advance

 

Simon

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...