The following is a detailed analysis of the use of WebBrowser controls in C #, the need for a friend to refer to the next
First let's start with a brief introduction to the WebBrowser control, which enables you to add Web content to a form. As shown in the form, I added the Baidu API, (Baidu Map API call blog has said)
Using this control is actually very simple
(1) The first step
just type in the Form_Load
Copy Code code as follows:
webbrowser1.navigate (Application.startuppath + "/map.html");/quote for the Web page code to store the address, note to use relative address without absolute address, so that only portability, Put the Web page in the debug directory of the program so that you can modify the page code directly in VS
webbrowser1.objectforscripting = this; Show
(2) The second step
Some students may need to call some of the variable data in the WebBrowser control in form. Let's say I want to call the distance between the two points measured in the Baidu map. This is the first time you add the following code to your Web page file:
Copy Code code as follows:
Mydis.addeventlistener ("Drawend", Function (e)//This is the code to measure the distance from Baidu
{result1=e.distance;
alert (RESULT1);
});
function getdistance ()//This paragraph writes itself, returns the value of the distance
{return result1;}
These are the Web Parts
Then in the form, to get the distance in the Web, use the following code:
Copy Code code as follows:
var s = webBrowser1.Document.InvokeScript ("getdistance");/quotation marks are function names, note that the variable should be in var type
Then, by hight = Convert.ToInt32 (s), you can convert the var to int, and you can refer to it at random.