Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Customizing the Winfom WebBrowser control

Customizing the Winfom WebBrowser control

Scheduled Pinned Locked Moved .NET (Core and Framework)
htmlquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    astibich2
    wrote on last edited by
    #1

    I am using the Winform's WebBrowser control to display HTML documents in my application. Now I need to draw a line above a certain HTML element in the document, and I'm hitting a road blocks. First, I tried to simply paint a line above the element, but quickly found that the WebBrowser doesn't support the paint event. Next, I tried to just position a thin, "line-like" control above the HTML element. I know the position of the element within the document, but to position the control properly, I'd need the WebBrowser scroll position. I'm reading that you can't read the scroll position, or receive scroll events from the WebBrowser control. Anyone have a plan C? Thanks, Aaron

    N 1 Reply Last reply
    0
    • A astibich2

      I am using the Winform's WebBrowser control to display HTML documents in my application. Now I need to draw a line above a certain HTML element in the document, and I'm hitting a road blocks. First, I tried to simply paint a line above the element, but quickly found that the WebBrowser doesn't support the paint event. Next, I tried to just position a thin, "line-like" control above the HTML element. I know the position of the element within the document, but to position the control properly, I'd need the WebBrowser scroll position. I'm reading that you can't read the scroll position, or receive scroll events from the WebBrowser control. Anyone have a plan C? Thanks, Aaron

      N Offline
      N Offline
      Nicholas Butler
      wrote on last edited by
      #2

      I've run into a similar problem recently. My plan C was to modify the html and use WebBrowser.DocumentText. I also wrote this, which might be useful:

      private void SaveScrollPosition()
      {
      if ( Loading ) return;

      var document = _Control.Document;
      if ( document == null ) return;

      var body = document.Body;
      if ( body == null ) return;

      if ( body.ScrollLeft != 0 || body.ScrollTop != 0 )
      {
      ScrollPositionX = body.ScrollLeft;
      ScrollPositionY = body.ScrollTop;
      return;
      }

      // for html with a DOC tag
      var htmls = document.GetElementsByTagName( "HTML" );
      if ( htmls == null ) return;
      if ( htmls.Count == 0 ) return;

      var html = htmls[ 0 ];
      if ( html == null ) return;

      if ( html.ScrollLeft != 0 || html.ScrollTop != 0 )
      {
      ScrollPositionX = html.ScrollLeft;
      ScrollPositionY = html.ScrollTop;
      return;
      }
      }

      Nick

      ---------------------------------- Be excellent to each other :)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups