C # Reference WebBrowser

xiaoxiao2021-03-19  224

Run this routine

VS.NET 2003 with IE Browser

How do you easily create your own IE browser? Mircosoft provides a COM component for us to use. This component is an AtiveX control. In fact, many window browsers such as Myie, TE are used this control. Let's talk about how to use it in C #.

Create a window Using the program Right-click on the Toolbox Some Card "Add / Remove the" COM Components "to select the Microsoft Web Browser control.

3. Press OK to appear in the toolbox.

4, now drag and drop it up to the form, then drag and drop a TextBox for input URL, and several Button used to implement "advancement", "back", "browse", "refresh". Drain the layout, as shown

5, encoding. The following is a few buttons event functions.

// 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 ();} // reverse private void btnBack_Click (object sender, System.EventArgs e) {this.axWebBrowser1.GoBack ();} // proceeds private void btnNext_Click (object sender, System.EventArgs e) {this.axWebBrowser1.GoForward ();} // stop 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, the compilation is running to see the results of the operation

VS.NET helps us do a touch of conversion from COM components to managed components. If you don't use VS.NET, you can also use the AXIMP tool to handle: AxImp C: /Windows/system/shdocvw.dll, generate axshdocvw.dll And shdocvw.dl, then reference it in the code.

Mike from http://sunrise.szu.cn

转载请注明原文地址:https://www.9cbs.com/read-130292.html

New Post(0)