How to change the HTML elements loaded by WebBrowser (hide scroll bars) and render as modified

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.