Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3280912
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:45:27+00:00 2026-05-17T19:45:27+00:00

Good night, I would like to know how can I highlight a part of

  • 0

Good night,

I would like to know how can I highlight a part of the text contained in a TextBox, Label (preferably) or RichTextBox. For example, given the string

“This is a test.”,

I would like the control to show “This is a test.”. Is there any easy way I can do it?

Thank you very much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:45:28+00:00Added an answer on May 17, 2026 at 7:45 pm
    RichTextBox r = new RichTextBox();
    r.Text = "This is a test";
    r.Select(r.Text.IndexOf("test"), "test".Length);
    r.SelectionFont = new Font(r.Font, FontStyle.Italic);
    r.SelectionStart = r.Text.Length;
    r.SelectionLength = 0;
    

    Something to that effect will work and remove the selection.

    EDIT
    It should be relatively easy to encapsulate in your own method. You could even make an extension:

    public static class Extensions
    {
        public static void StyleText(this RichTextBox me, string text, FontStyle style)
        {
            int curPos = me.SelectionStart;
            int selectLen = me.SelectionLength;
            int len = text.Length;
            int i = me.Text.IndexOf(text);
    
            while (i >= 0)
            {
                me.Select(i, len);
                me.SelectionFont = new Font(me.SelectionFont, style);
                i = me.Text.IndexOf(text, i + len);
            }
    
            me.SelectionStart = curPos;
            me.SelectionLength = selectLen;
        }
    }
    

    and then use it like:

    richTextBox1.Text = "This is a test";
    richTextBox1.StyleText("test", FontStyle.Italic);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good morning, I have mysql queries where I would like to calculate percentage of
Good day, just a quick question: I would like to bind a table to
Good night, in my application I access my database through Hibernate. I want to
Good Day, Can someone confirm what was said at the bottom of this post
Good day I have a custom TextBox that has a IndicatorTextBox.ui.xml file as well
Good day, I have like 15 images I need to be buttons. I have
So, I'd like to be able to make a call x = MyClass.new('good morning',
I am using curl from a BASH shell. I would like to create a
Good night, I am currently working on a very simple lexical analiser for human
good night: I want to mouse over .slide show the #panel , then click

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.