Results 1 to 4 of 4

Thread: RichTextBox BackColor

  1. #1

    Thread Starter
    Addicted Member cutamacious's Avatar
    Join Date
    May 2001
    Location
    INDIA >> Andhra Pradesh >> Hyderabad
    Posts
    185

    Question RichTextBox BackColor

    Hi all

    How do we change the backcolor of a portion of text in a RichTextbox. I know that there is a method to change the font color of a portion of text in the richtextbox but I want to know how to change the back color.


    Thanx in advance
    Cute Member

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: RichTextBox BackColor

    Try
    Code:
    private void Detail_Format(object sender, System.EventArgs eArgs) 
    { 
        RichTextBox1.BackColor = System.Drawing.Color.DarkGoldenrod; 
    }

  3. #3

    Thread Starter
    Addicted Member cutamacious's Avatar
    Join Date
    May 2001
    Location
    INDIA >> Andhra Pradesh >> Hyderabad
    Posts
    185

    Re: RichTextBox BackColor

    Quote Originally Posted by Hack
    Try
    Code:
    private void Detail_Format(object sender, System.EventArgs eArgs) 
    { 
        RichTextBox1.BackColor = System.Drawing.Color.DarkGoldenrod; 
    }
    This works for the entire richtextbox. I dont want to change the backcolor of the entire RichTextBox only of the selected text in the rich text box. The RichTextBox might contain more than 2 words in it. If a portion of the 1st word is selected, then the back color of the selected portion should change (of course this will be in button click event or some thing compatible)
    Cute Member

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,296

    Re: RichTextBox BackColor

    I've not used the RTB myself but it looks like it doesn't support adding a background colour to a portion of text directly. It seems that you would have to manipulate the Rtf property yourself, which is obviously best avoided if possible. Check out this extended RichTextBox that adds just that functionality. I think the code is in VB.NET but it shouldn't be too hard to convert. Try the converter in my signature if you need help, but keep in mind that it's not 100% reliable (although it does a good job) and it won't always produce the most efficient code.

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