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.