Results 1 to 17 of 17

Thread: Change Richtextbox Forecolor

  1. #1

    Thread Starter
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Change Richtextbox Forecolor

    I just noticed the richtextbox control doesn't have a forecolor property. How do you change it then?
    Last edited by SeanK; Apr 26th, 2006 at 10:20 AM.
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Change Richtextbox Forecolor

    text colour is specified using the .SelColor property

  3. #3
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: Change Richtextbox Forecolor

    It has many forecolors
    You can use the SelColor property to change the color of the selected text.
    Frans

  4. #4

    Thread Starter
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: Change Richtextbox Forecolor

    Quote Originally Posted by Frans C
    It has many forecolors
    You can use the SelColor property to change the color of the selected text.
    I want the entire textbox to be the same color just like if I changed the forecolor of a standard textbox.

    Do I have to select EVERYTHING in it, programmatically, to do that?
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  5. #5
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Change Richtextbox Forecolor

    yeah:

    VB Code:
    1. With RichTextBox1
    2.     .SelStart = 0
    3.     .SelStart = Len(.Text)
    4.     .SelColor = vbRed
    5. End With

    or set the color before you put the text in:
    VB Code:
    1. With RichTextBox1
    2.     .SelColor = vbRed
    3.     .SelText = "this is my red text"
    4. End With

  6. #6

    Thread Starter
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: Change Richtextbox Forecolor

    From what I'm hearing, I need to have text in there before setting it, right?
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  7. #7
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Change Richtextbox Forecolor

    no, you can set the text colour before placing the text, as i demonstrated in the 2nd part of post #5

  8. #8

    Thread Starter
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: Change Richtextbox Forecolor

    I have created a 5 step wizard which walks the user through a particular process. My final frame will contain a richtextbox which will display all of the selections made on the prior 4 wizard frames.

    I'm not going to have anything in the textbox until the end, and I was hoping to set the forecolor, in design, so it would be set. But, again, from what I've seen, I will have to wait until my "Next" button is clicked on the 4th frame to change the color. Would this be a valid assessment?
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  9. #9
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Change Richtextbox Forecolor

    you can place RichTextBox1.SelColor = vbRed anywhere in your form code that is going to be executed prior to setting the text.

    Placing it just before you set the text seems the most logical to manage your code.

    Remember to set the .SelText = to whatever text, not .Text otherwise you will lose the formatting.

  10. #10

    Thread Starter
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: Change Richtextbox Forecolor

    Ok. Thanks for the help.
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  11. #11

    Thread Starter
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: Change Richtextbox Forecolor

    I was a bit premature in resolving this. Here is what I have
    VB Code:
    1. Private Sub DisplaySelections()
    2. With RichtTextBox1
    3.     .SelStart = 0
    4.     .SelStart = Len(.Text)
    5.     .SelColor = vbGreen
    6.     .Text = lblAckDate.Caption & DoubleSpace
    7.     .Text = .Text & cboContacts.Text & vbNewLine
    8.     .Text = .Text & cboTitle.Text & vbNewLine
    9.     .Text = .Text & cboProvider.Text & vbNewLine
    10.     .Text = .Text & cboStreet.Text & vbNewLine
    11.     .Text = .Text & cboCity.Text & DoubleSpace
    12. End With
    13. End Sub
    Yet, the forecolor of the rtb remains black. Why?
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  12. #12
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Change Richtextbox Forecolor

    Quote Originally Posted by bushmobile
    Remember to set the .SelText = to whatever text, not .Text otherwise you will lose the formatting.
    VB Code:
    1. Private Sub DisplaySelections()
    2.     With RichtTextBox1
    3.         .SelStart = 0
    4.         .SelStart = Len(.Text) ' if there's nothing in the rtb you can leave this line out
    5.         .SelColor = vbGreen
    6.         .[B]SelText[/B] = lblAckDate.Caption & DoubleSpace _
    7.                  & cboContacts.Text & vbNewLine _
    8.                  & cboTitle.Text & vbNewLine _
    9.                  & cboProvider.Text & vbNewLine _
    10.                  & cboStreet.Text & vbNewLine _
    11.                  & cboCity.Text & DoubleSpace _
    12.     End With
    13. End Sub

  13. #13

    Thread Starter
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: Change Richtextbox Forecolor

    I admit, I did miss that.

    So, I went back and changed .Text to .SelText and the following resulted:
    Code:
    Wednesday, April 26, 2006 <=== this changed to green
    
    Sean Seank                              <===from here on down remained black.
    Near Sighted Programmer
    1234 Memory Lane 
    Boston, MA
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  14. #14
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Change Richtextbox Forecolor

    did you try the code i suggested in post #12

  15. #15

    Thread Starter
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: Change Richtextbox Forecolor

    Please explain why this works
    VB Code:
    1. .SelText = lblAckDate.Caption & DoubleSpace _
    2.                  & cboContacts.Text & vbNewLine _
    3.                  & cboTitle.Text & vbNewLine _
    4.                  & cboProvider.Text & vbNewLine _
    5.                  & cboStreet.Text & vbNewLine _
    6.                  & cboCity.Text & DoubleSpace _
    And this doesn't
    VB Code:
    1. .SelText = lblAckDate.Caption & DoubleSpace
    2.                  .SelText = .SetText & cboContacts.Text & vbNewLine
    3.                  .SelText = .SetText cboTitle.Text & vbNewLine
    4.                  .SelText = .SetText cboProvider.Text & vbNewLine
    5.                  .SelText = .SetText cboStreet.Text & vbNewLine
    6.                  .SelText = .SetText cboCity.Text & DoubleSpace
    I don't get it.
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  16. #16
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 2011
    Location
    WNY
    Posts
    451

    Re: Change Richtextbox Forecolor

    Just try this.

    vb Code:
    1. Private Sub DisplaySelections()
    2.           With RichtTextBox1
    3.               .SelColor = Color.Green
    4.               .Text = lblAckDate.Caption & DoubleSpace _
    5.                        & cboContacts.Text & Environment.Newline _
    6.                        & cboTitle.Text & Environment.Newline _
    7.                        & cboProvider.Text & Environment.Newline _
    8.                        & cboStreet.Text & Environment.Newline _
    9.                        & cboCity.Text & DoubleSpace _
    10.           End With
    11.       End Sub

    When there is no text, then there is nothing to select(hence .SelStart & .SelLength). If you do then your changing the color of nothing, then everything else added after does not change the color.

    So by using .SelColor() ONLY before adding any text, will effect any text added afterwards.
    Last edited by DavesChillaxin; Feb 9th, 2012 at 04:13 PM.
    Please rate if my post was helpful!
    Per favore e grazie!




    Code Bank:
    Advanced Algebra Class *Update | True Gradient Label Control *Dev | A Smarter TextBox *Update | Register Global HotKey *Update
    Media Library Beta *Dev | Mouse Tracker (Available in VB.net and C#.net) *New | On-Screen Numpad (VB.net) *New

  17. #17
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 2011
    Location
    WNY
    Posts
    451

    Re: Change Richtextbox Forecolor

    Quote Originally Posted by SeanK View Post
    Please explain why this works
    VB Code:
    1. .SelText = lblAckDate.Caption & DoubleSpace _
    2.                  & cboContacts.Text & vbNewLine _
    3.                  & cboTitle.Text & vbNewLine _
    4.                  & cboProvider.Text & vbNewLine _
    5.                  & cboStreet.Text & vbNewLine _
    6.                  & cboCity.Text & DoubleSpace _
    And this doesn't
    VB Code:
    1. .SelText = lblAckDate.Caption & DoubleSpace
    2.                  .SelText = .SetText & cboContacts.Text & vbNewLine
    3.                  .SelText = .SetText cboTitle.Text & vbNewLine
    4.                  .SelText = .SetText cboProvider.Text & vbNewLine
    5.                  .SelText = .SetText cboStreet.Text & vbNewLine
    6.                  .SelText = .SetText cboCity.Text & DoubleSpace
    I don't get it.
    This doesn't work because your changing the selected text... over and over again. Just use RichTextBox1.Text &= ""

    Anything with "Sel" in it stands for selected, which only applies to the text that is selected by the user or by you manually.
    Please rate if my post was helpful!
    Per favore e grazie!




    Code Bank:
    Advanced Algebra Class *Update | True Gradient Label Control *Dev | A Smarter TextBox *Update | Register Global HotKey *Update
    Media Library Beta *Dev | Mouse Tracker (Available in VB.net and C#.net) *New | On-Screen Numpad (VB.net) *New

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