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 ~