(1) create a Windows Application Form, name it a web browser, and add corresponding controls to the form, as shown below:
(2) Add the corresponding event response code for the corresponding control. The complete code is as follows:
Using system; using system. Collections. Generic;
Using system. componentmodel; using system. Data;
Using system. Drawing; using system. text;
Using system. Windows. forms; using system. IO;
Namespace Web Browser
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}
Private void navigate (string address)
{
If (string. isnullorempty (Address ))
Return;
If (address. Equals ("about: blank") return;
If (! Address. startswith ("http: //") Address = "http: //" + address;
Try {
Cursor. Current = cursors. waitcursor; webbrowser1.navigate (New uri (Address ));
}
Catch (system. uriformatexception)
{Return ;}
Finally {cursor. Current = cursors. Default ;}
}
Private void form1_load (Object sender, eventargs E)
{
Toolstrip1.imagelist = imagelist1;
Tbback. imageindex = 0;
Tbforward. imageindex = 1;
Tbrefrash. imageindex = 2;
Tbhome. imageindex = 3;
}
Private void combobox1_keydown (Object sender, keyeventargs E)
{If (E. keycode = keys. Enter ){
Navigate (combobox1.text );
Combobox1.items. Add (combobox1.text );
}
}
Private void tbback_click (Object sender, eventargs E)
{
Webbrowser1.goback ();
}
Private void tbforward_click (Object sender, eventargs E)
{
Webbrowser1.goforward ();
}
Private void tbrefrash_click (Object sender, eventargs E)
{
I f (! Webbrowser1.url. Equals ("about: blank "))
{
Webbrowser1.refresh ();
}
}
Private void tbhome_click (Object sender, eventargs E)
{
Webbrowser1.gohome ();
}
Private void combobox#selectedindexchanged (Object sender, eventargs E)
{
Navigate (combobox1.text );
}
Private void open toolstripmenuitem_click (Object sender, eventargs E)
{
Openfiledialog1.showdialog ();
Webbrowser1.documenttext = file. readalltext (openfiledialog1.filename, encoding. getencodin ("gb2312 "));
}
Private void disable toolstripmenuitem_click (Object sender, eventargs E)
{
This. Close ();
}
Private void form1_resize (Object sender, eventargs E)
{
Webbrowser1.width = This. Width-25;
Webbrowser1.height = This. Height-130;
Combobox1.width = This. Width-55;
}
Private void toolstripbutton#click (Object sender, eventargs E)
{
Webbrowser1.gosearch ();
}
}
}
(3) program description: This program only implements a web browser with simple functions. A powerful web browser is being created. It aims to give beginners an interesting role.