Customizing the Winfom WebBrowser control
-
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
-
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
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 :)