How to change the HTML elements loaded by WebBrowser
Method 1: Add code to the event after the Web page is loaded, I just modified the page does not appear scroll bar, because scroll bar i rewrite.
1 #regionA function that executes a callback after the Web page is loaded (private)2 3 /// <summary>4 ///The function that executes the callback after the Web page is loaded, in which the parameters of the scrollbar are initialized5 /// </summary>6 Private voidWebbrowser1_documentcompleted (Objectsender, WebBrowserDocumentCompletedEventArgs e)7 {8 if( This. Webbrowser1.readystate = =webbrowserreadystate.complete)9 {TenHtmlElementCollection bodys= This. WebBrowser1.Document.GetElementsByTagName ("Body"); OneHtmlElement body=NULL; A if(Bodys. Count>0) -body=bodys[0]; - if(Body! =NULL ) the { - if(body.) Style! =NULL ) -Body. Style + ="Overflow:hidden;"; - Else +Body. Stle ="Overflow:hidden;"; - } + } + } A #endregion
Method 2: Modify the Documenttex content directly
1 Private voidWebbrowser1_documentcompleted (Objectsender, WebBrowserDocumentCompletedEventArgs e)2 {3 if( This. Webbrowser1.readystate = =webbrowserreadystate.complete)4 {5 Try6 {7 stringStrhtml= This. Webbrowser1.documenttext;8strHTML ="here, change where you want to move.";9 This. Webbrowser1.documenttext =strhtml; One } A Catch - { - } the - } -}
Method 3: Everybody says that.
This.webBrowser1.Document.Body.SetAttribute ("Scroll", "no");
Summary: Here to explain the difference between this method and the first method, the first method modified, in the rendered page right-click View source code is not see the modified content,
But you can see it in the webBrowser1.Document.Body.OuterHtml attribute.
The second method after modifying the right-click to see the source code can also be seen, about other more in-depth differences, as a rookie I still did not care,
Method 3, not very flexible, sometimes useless
I'm using the first method.
How to change the HTML elements loaded by WebBrowser (hide scroll bars) and render as modified