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
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:
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:
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.