RichTextBox BackColor-VBForums
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
    184

    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
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: RichTextBox BackColor

    Try
    Code:
    private void Detail_Format(object sender, System.EventArgs eArgs) 
    { 
        RichTextBox1.BackColor = System.Drawing.Color.DarkGoldenrod; 
    }
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  3. #3

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

    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
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    88,259

    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.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.