Web|webbrowser Control | creating
Running this routine requires
Vs.net 2003
Equipped with IE browser
How to create your own IE browser simply? Mircosoft provides a COM component for us to use, this component is a AtiveX control, and in fact many Windows browsers such as Myie and TE use this control. Let's talk about how to use it in C #.
Create a window to use the program
Right-click one of the toolbox tabs to add/remove items ... COM components select the Microsoft Web Browser control.
3, the control appears in the toolbox after the confirmation.
4, now drag it onto the form, and then drag and drop a textbox for the input URL, as well as several button to achieve "forward", "Back", "Browse", "refresh" and other functions. Arrange the layout as shown
5, coding. Here are the event functions for several buttons.
Browse
private void Btngo_click (object sender, System.EventArgs e)
{
Object nullobject = new Object ();
this.axWebBrowser1.Navigate (
this.txtUrl.Text,
ref Nullobject,
ref nullobject,
ref nullobject,
ref Nullobject
);
}
Home
private void Btnhomepage_click (object sender, System.EventArgs e)
{
This.axWebBrowser1.GoHome ();
}
Back off
private void Btnback_click (object sender, System.EventArgs e)
{
This.axWebBrowser1.GoBack ();
}
Forward
private void Btnnext_click (object sender, System.EventArgs e)
{
This.axWebBrowser1.GoForward ();
}
Stop it
private void Btnstop_click (object sender, System.EventArgs e)
{
This.axWebBrowser1.Stop ();
}
Refresh
private void Btnrefresh_click (object sender, System.EventArgs e)
{
This.axWebBrowser1.Refresh ();
}
6, compile run can see the results of the operation
Vs.net helped us do the conversion from COM components to managed components, and if you don't use vs.net, you can also use the AxImp tool to manually convert: AxImp c:\windows\system\shdocvw.dll, which generates AxSHDocVw.dll and Shdocvw.dl, and then refer to it in your code.