Results 1 to 3 of 3

Thread: Format Text

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    198

    Smile Format Text

    Hi

    This is going to be quite an explanation:

    on the main form of my application, I have a Rich Text Box which is where the user will be entering information. The text is black.

    then, i have a button which calls the dialogue "Notes"

    A dialogue appears, with a rich text box.

    the user should then be able to enter text into the box, click "OK", and the text entered into the Notes dialogue be inserted to the rich text box on the main form -- with the font colour "Red". The rest of the text in the main rich text box on the main form should remain black.

    Help appreciated!

    Many thanks,

    M

  2. #2
    Addicted Member
    Join Date
    Mar 2007
    Posts
    163

    Re: Format Text

    Hi this could be one solution:

    When you create your dialog "Notes" in the constructor you can pass an instance of your main form
    vb Code:
    1. Dim notesForm as new Notes(me)

    You then add teh text to your rich text box and click your ok button which will I presume close your Notes form and then using the main form object you can call a sub in your main form class that will add the new text to the main forms rich text box... The add text can look something like this...

    vb Code:
    1. Public Sub AddText(ByVal text As String)
    2.         Me.RichTextBox1.AppendText(text)' append to the existing text
    3.         Me.RichTextBox1.Select(RichTextBox1.Text.IndexOf(text), text.Length)'select the new text
    4.         Me.RichTextBox1.SelectionColor = Color.Red'make it red
    5.     End Sub

    After doing this you will still have to return the rich text color back to black ... but I'll leave that to you

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Format Text

    Something like this

    Code:
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim d As New Dialog1
            Dim dr As DialogResult = d.ShowDialog
            If dr = Windows.Forms.DialogResult.OK AndAlso d.RichTextBox1.TextLength > 0 Then
                d.RichTextBox1.SelectAll()
                d.RichTextBox1.SelectionColor = Color.Red
                Me.RichTextBox1.SelectedRtf = d.RichTextBox1.SelectedRtf
            End If
        End Sub
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width