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 7702781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:18:23+00:00 2026-05-31T23:18:23+00:00

OK people, I am creating a class that basically has to interact with a

  • 0

OK people, I am creating a class that basically has to interact with a RichTextBox in c# .net. One of its primary functions is to detect if the user typed a special word, if it finds a match it has to change the word’s color (like in word processor).

The thing is that I am not sure how to go about doing it in an efficient way cause I was thinking about doing a search every time the text in the RTB (RichTextBox) is modified but it would be too inefficient to search the whole RTB every time the user types a new word (considering that the text in the RTB is long).

I found a way to get the last character typed in the RTB and determine if a word was formed and then check if it was a special word, but the problem is that if the RTB’s text is modified by functions or by pasting text then it would not work. So, I have to take into consideration that the RTB’s text can be modified in many ways.

So, would it be efficient to do a full search in the RTB every time the text is changed to find the special words? (taking into account that the text on it may be long) or is there any other approach you guys have in mind?

EDIT:—————————-

Well in case somebody is interested I found a way to solve the problem.

I used an integer in my class to keep track of the current selection position (the current or last know position of the cursor in the RTB) by updating it each time the selection was changed in the RTB with the event RichTextBox_SelectionChanged. Like this:

private void richTextBox1_SelectionChanged(object sender, EventArgs e)
{
   LastCursorPosition = CurrentCursorPosition;
   CurrentCursorPosition = richTextBox1.SelectionStart;
   CursorsDifferences = CurrentCursorPosition - LastCursorPosition;

}

this will ensure that CurrentCursorPosition will be updated every time the user types a character or modifies the text in the RTB and LastCursorPosition will hold, well do I have to say it? Then the differences in the cursors positions will be saved on CursorsDifferences that way if the user pasted something into the RTB CursorsDifferences will tell you the length of the string inserted. Based on that you can do the search from
LastCursorPosition to CurrentCursorPosition.

NOTE:
Searching from LastCursorPosition to CurrentCursorPosition might not be accurate because LastCursorPosition might NOT be the beginning of a word therefore you have to find the previous ‘ ‘(whitesapce) or ‘\n’ (newline) and get the position of the character in front of a ‘ ‘ or ‘\n’ and do the search based on the position, same thing applies to CurrentCursorPosition.

  • 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-31T23:18:25+00:00Added an answer on May 31, 2026 at 11:18 pm

    Well in case somebody is interested I found a way to solve the problem.

    I used an integer in my class to keep track of the current selection position (the current or last know position of the cursor in the RTB) by updating it each time the selection was changed in the RTB with the event RichTextBox_SelectionChanged. Like this:

    private void richTextBox1_SelectionChanged(object sender, EventArgs e)
    {
       LastCursorPosition = CurrentCursorPosition;
       CurrentCursorPosition = richTextBox1.SelectionStart;
       CursorsDifferences = CurrentCursorPosition - LastCursorPosition;
    
    }
    

    this will ensure that CurrentCursorPosition will be updated every time the user types a character or modifies the text in the RTB and LastCursorPosition will hold, well do I have to say it? Then the differences in the cursors positions will be saved on CursorsDifferences that way if the user pasted something into the RTB CursorsDifferences will tell you the length of the string inserted. Based on that you can do the search from LastCursorPosition to CurrentCursorPosition.

    NOTE: Searching from LastCursorPosition to CurrentCursorPosition might not be accurate because LastCursorPosition might NOT be the beginning of a word therefore you have to find the previous ‘ ‘(whitesapce) or ‘\n’ (newline) and get the position of the character in front of a ‘ ‘ or ‘\n’ and do the search based on the position, same thing applies to CurrentCursorPosition.

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

Sidebar

Related Questions

I'm creating a utility class that will make it easier for people to parse
What do people recommend for creating popup's in ASP.Net MVC? I have used the
I am creating a page where people can post articles. When the user posts
I am creating a linq-to-sql model with EF, and have a class that works
I am creating a class that implements the composite pattern; the class is supposed
Hi I'm creating online shop. In this shope people online must be buy files
People always advised me that if I am doing some application that should use
I'm trying to reduce the code duplication that exists throughout my asp.net web forms.
I need to define a class that represents a real-life event -- like a
I was wondering if the overhead associated with creating a new class instead of

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.