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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:37:33+00:00 2026-05-12T13:37:33+00:00

I have a webbrowser control and I am able to get the selected word

  • 0

I have a webbrowser control and I am able to get the selected word by the user.
I am saving this word in a file and with it I am also saving its byte offset and length.

Lets says i have some text in my Web browser control as “Hello Hey Hello” lets say the user has selected last hello.

Now that word is saved with me along with other info like its length etc.

I need to provide a feature to highlight the selected word when the user reloads the file and sends me that word along with its length and byte offset

Is there any way to do it.

  • 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-12T13:37:33+00:00Added an answer on May 12, 2026 at 1:37 pm

    you’re going to need to import the Microsoft.mshtml assembly reference if you haven’t already, and add

    using mshtml;
    
            if (webBrowser1.Document != null)
            {
                IHTMLDocument2 document = webBrowser1.Document.DomDocument as IHTMLDocument2;
                if (document != null)
                {
                    IHTMLBodyElement bodyElement = document.body as IHTMLBodyElement;
                    if (bodyElement != null)
                    {
                        IHTMLTxtRange trg = bodyElement.createTextRange();
    
    
                        if (trg != null)
                        {
                            const String SearchString = "Privacy"; // This is the search string you're looking for.
                            const int wordStartOffset = 421; // This is the starting position in the HTML where the word you're looking for starts at.
                            int wordEndOffset = SearchString.Length;
                            trg.move("character", wordStartOffset);
                            trg.moveEnd("character", wordEndOffset);
    
                            trg.select();
                        }
                    }
                }
            }
    

    here is a snippet that might be helpful also:

            if (webBrowser1.Document != null)
            {
                IHTMLDocument2 document = webBrowser1.Document.DomDocument as IHTMLDocument2;
                if (document != null)
                {
                    IHTMLSelectionObject currentSelection = document.selection;
    
                    IHTMLTxtRange range = currentSelection.createRange() as IHTMLTxtRange;
                    if (range != null)
                    {
                       const String search = "Privacy";
    
                       if (range.findText(search, search.Length, 2))
                       {
                           range.select();
                       }
                    }
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WebBrowser control in a VB.NET WinForms app. I am able to
I'm developing automation program using winforms webbrowser control. I am able to get the
I have a WebBrowser control which shows some html. When user clicks some link
I can't find any doucmentation on this. I have a WebBrowser control for my
I have a webbrowser control which I navigate to an URL that contains this
I have a WebBrowser control and try to set onclick and href attributes on
Okay, I have a WebBrowser control in my VB.NET application that loads a PHP
I have a Windows Forms WebBrowser control embedded in my application. Is there any
We have a form that hosts the WebBrowser control. That is the only control
I have been using the .NET WebBrowser control in edit mode as part 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.