Analysis on the use of the WebBrowser control in c #

Source: Internet
Author: User

The following is a detailed analysis of the use of the WebBrowser control in c #. For more information, see

First, let's briefly introduce the webbrowser control, which allows you to add webpage content in the form ., I added Baidu api to form (this is a description in the Baidu map api call blog)

Using this control is actually very simple

(1) Step 1
As long as you enter

Copy codeThe Code is as follows:
WebBrowser1.Navigate (Application. startupPath + "/map.html"); // The address for storing the webpage code in quotation marks. Note that you do not need to use an absolute address to store the webpage code in the debug directory of the program, in this way, you can directly modify the webpage code in.
WebBrowser1.ObjectForScripting = this; // display


(2) Step 2
Some users may need to call variable data in some webBrowser controls in form. What should I do at this time. For example, I want to call the distance between the two points measured in Baidu map. Add the following code to the webpage file:

Copy codeThe Code is as follows:
MyDis. addEventListener ("drawend", function (e) // The distance measurement code provided by Baidu
{Result1 = e. distance;
Alert (result1 );
});
Function getdistance () // The value of the distance written by the user.
{Return result1 ;}


The above is the web Part
To obtain the distance from the web in form, use the following code:

Copy codeThe Code is as follows:
Var s = webBrowser1.Document. InvokeScript ("getdistance"); // The function Name of the function is enclosed in quotation marks. Note that the variable must be of the var type.


Then, you can Convert the var type to the int type through hight = Convert. ToInt32 (s); and then reference it at will.

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.