C # How to Use the webbrowser control to create a simple IE browser (cainiao-level)

Source: Internet
Author: User

During the design processProgramEmbedded in a simple browser. However, I have read the relevant books without a good example program, so I will summarize the information collected from the Internet to facilitate future users.

First, add a combox and a webbrowser to the form. Key partCodeAs follows:

Initialization:

Code
  Private   Void Form1_load ( Object Sender, eventargs E)
{
Combobox1.text =   " Http://www.cnblogs.com/finallyliuyu/ " ;
Combobox1.items. Add ( " Http://news.qq.com/newsgn/sdbd/zdtj/zdtj.htm " );
Combobox1.items. Add ( " Http://news.ifeng.com/history/1/jishi/ " );
Combobox1.items. Add ( " Http://tech.qq.com/scroll/index.htm " );
}

View the URL represented by combobox1.text

1 Private   Void Button#click ( Object Sender, eventargs E)
2 {
3StringURL=Combobox1.text. Trim ();
4
5Webbrowser1.navigate (URL );
6}

Return to the previous web page

 

1 // Back
2 Private   Void Button2_click ( Object Sender, eventargs E)
3 {
4Webbrowser1.goback ();
5
6}

Click the link on the webpage. Instead of starting IE, use webbrowser to continue browsing.

 

Code4
Private   Void Webbrowser1_newwindow ( Object Sender, canceleventargs E)
{
E. Cancel =   True ;
If (Webbrowser1.document. activeelement ! =   Null )
{
Webbrowser1.navigate (webbrowser1.document. activeelement. getattribute ( " Href " ));
Combobox1.text = Webbrowser1.document. activeelement. getattribute ( " Href " );
}

}

// After each Webpage Browsing, the text in combox_url changes to the URL of the current webpage

 

  Private   Void Webbrowser1_navigated ( Object Sender, webbrowsernavigatedeventargs E)
{
Combobox1.text = Webbrowser1.url. tostring ();
}

 

After completing the above functions, a simple browser is ready. This is the first time I posted a blog on cnblogs. Please pat the bricks. In the future, I will launch some of my own programs and experiences, and share them with my cainiao friends ~

 

 

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.