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

  • SEARCH
  • Home
  • 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 8872275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:11:03+00:00 2026-06-14T18:11:03+00:00

I have a richTextbox which some texts inside. Currently, the orange is located in

  • 0

I have a richTextbox which some texts inside. Currently, the “orange” is located in the line 3….so how can i get the line of “orange”. My code doesn’t work =(

enter image description here

My C# code:

private void button1_Click(object sender, EventArgs e)
    {
        string orange = "orange";
        int a = richTextBox1.Text.IndexOf(orange);
        var b = richTextBox1.Lines.ElementAt(a);

        textBox1.Text = b.ToString();

    }
  • 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-06-14T18:11:05+00:00Added an answer on June 14, 2026 at 6:11 pm

    How about

    private void button1_Click(object sender, EventArgs e)
    {
        string orange = "orange";
    
        textBox1.Text = richTextBox1.GetLineFromCharIndex(
          richTextBox1.Find(orange)
        );
    }
    

    Refer to the documentation of RichTextBox.GetLineFromCharIndex(int) and RichTextBox.Find(string)

    Basically Find(string) returns the index of the beginning of the string in the text (or -1 if the string wasn’t found), this index is passed to GetLineFromCharIndex(int) which in turn retrieves the line number of the specified index.
    You may have to handle the special case where your string was not found and -1 was returned from Find(string).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a RichTextBox and I add some texts programatically. I need to display
I have a RichTextBox control on a form with some text, some of which
I have an application which monitors some devices. I can send a string to
I have some code in place currently to intercept all Cut, Copy and Paste
I have a RichTextBox which contains links posted by the users. The problem is
I have a form which has a RichTextBox docked to the left and DataGridView
I have Winform application,which does some operation in loops (file access, copy file, ....).
I've got a richtextbox, that I plan on saving to a database, which can
I have a course work for which I have to make a (as advanced
I have some xaml code for a silverlight project sort of like below: <Grid>

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.