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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:42:15+00:00 2026-05-22T01:42:15+00:00

I was wondering if its possible to get the absolute position of specific HTML

  • 0

I was wondering if its possible to get the absolute position of specific HTML element I have loaded in webbrowser control with C#.

I tried almost all of the options that .Net provides..
none of them give me the correct position. all of them give me 0 for Y coordinate.. the element is definitely is not in 0..

does anybody have any solution or idea to solve this?

  • 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-22T01:42:16+00:00Added an answer on May 22, 2026 at 1:42 am

    here is the solution I got so far:


    // set the size of our web browser to be the same size as the image
    int width, height;
    width = webBrowser1.Document.Images[0].ClientRectangle.Width;
    height = webBrowser1.Document.Images[0].ClientRectangle.Height;

    webBrowser1.Width = width;
    webBrowser1.Height = height;
    
    //scroll vertically to that element
    webBrowser1.Document.Images[0].OffsetParent.ScrollIntoView(true);
    
    //calculate x, y offset of the element
    int x = webBrowser1.Document.Images[s].OffsetRectangle.Left + 
    webBrowser1.Document.Images[s].OffsetParent.OffsetRectangle.Left + 
    webBrowser1.Document.Images[s].OffsetParent.OffsetParent.OffsetRectangle.Left+
    webBrowser1.Document.Images[s].OffsetParent.OffsetParent.OffsetParent.OffsetRectangle.Left+
    webBrowser1.Document.Images[s].OffsetParent.OffsetParent.OffsetParent.OffsetParent.OffsetRectangle.Left;
    
    int y = webBrowser1.Document.GetElementsByTagName("HTML")[0].ScrollTop;
    
    //now scroll to that element
    webBrowser1.Document.Window.ScrollTo(x, y);
    

    now this code works perfectly.. but there is an issue with calculating the offsets. I need to calculate the offsetparent of the element then calculate the offsetparent of the offsetparent etc.. I need to do that dynamically not adding it one by one.. I don’t know how to do that. any ideas?

    EDIT:
    here is my last and final version and it works with any html element it will find the absolute position of any element I want..

       public int getXoffset(HtmlElement el)
         {
             //get element pos
             int xPos = el.OffsetRectangle.Left;
    
             //get the parents pos
             HtmlElement tempEl = el.OffsetParent;
             while (tempEl != null)
             {
                 xPos += tempEl.OffsetRectangle.Left;
                 tempEl = tempEl.OffsetParent;
             }
    
             return xPos; 
         }  
    
         public int getYoffset(HtmlElement el)
         {
             //get element pos
             int yPos = el.OffsetRectangle.Top;
    
             //get the parents pos
             HtmlElement tempEl = el.OffsetParent;
             while (tempEl != null)
             {
                 yPos += tempEl.OffsetRectangle.Top;
                 tempEl = tempEl.OffsetParent;
             }
    
             return yPos;
         }
    

    then use the position with:

     //now scroll to that element
     webBrowser1.Document.Window.ScrollTo(x, y);
    

    done!

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

Sidebar

Related Questions

I am wondering if its possible to get $(this).scrollTop() value after an anchor jump.
I'm wondering if it's possible to get the address of an individual element of
I am wondering if its possible to have a an (||)or or (&&)and operator
I am wondering if its possible to get the size of the content (
I'm wondering if its possible to join together IEnumerable's. Basically I have a bunch
I am wondering if its possible to have Netbeans display PHP Documentation for functions/methods/classes
I am wondering if its possible to get my android application to save a
Just wondering if its possible to get the x/y location of the mouse from
Hi Guys [and girls] :) Just wondering whether it's possible to get the absolute
I'm wondering if its possible to have a property/field in a class that is

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.