Create your own IE with C # and Microsoft WebBrowser controls

Source: Internet
Author: User
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.



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.