CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 1999
    Posts
    84

    Change the font color

    Hello,

    I have to change the color of the text in the text ctrl. If the text is received from one text box then its color should be different from the one received to the same the text box from another text box.
    That is if the text is received from Text2 to text1 then it should be in red. If the text is received from Text3 to text1 then it should be green.

    This is urgent, Please help me out


    Thanks
    Harini

  2. #2
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Change the font color

    Use the RichTextBox control when you have to display differently formatted text in the same box.


  3. #3
    Join Date
    Jul 1999
    Posts
    84

    Re: Change the font color

    Thank u for ur response.
    After posting the query I have placed the Rich Text box ctrl.
    I am able to color the text from different text boxes differently. But the problem is when the text is sent from the same text box for the second time, every thing is changing its color to the color of the present line.

    Thanks
    Harini

  4. #4
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Change the font color

    The following code changes the color in a rich text box, preserving the previous color. I hope you can modify it to suit your needs.


    private Sub Command1_Click()
    Dim OldLen as Integer
    'Save the length of the text
    OldLen = len(RichTextBox1.Text)
    'set the insertion point at the end of the the rich text box
    RichTextBox1.SelStart = OldLen
    'Insert a newline character at the end, you could use vbNewLine
    RichTextBox1.SelText = vbCrLf
    'Compute the newlength. It is basically oldlen + 2
    OldLen = len(RichTextBox1.Text)
    'This adds the new text at the end of what is already in the rtb.
    RichTextBox1.SelText = Text1.Text
    'Selection starts at the old length (just before the new text)
    RichTextBox1.SelStart = OldLen
    'You know this...
    RichTextBox1.SelLength = len(Text1.Text)
    'Change the color depending upon the choice
    If Option1.Value = true then RichTextBox1.SelColor = vbRed else RichTextBox1.SelColor = vbBlue
    'Finally remove the selection
    RichTextBox1.SelLength = 0
    End Sub





  5. #5
    Join Date
    Jul 1999
    Posts
    84

    Re: Change the font color

    Hello Shree,

    Thank you for the solution. I am trying to implement it my robust code. If I have any more doubts I will get back to you

    Thanks
    Harini

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

Featured