On the use of WebBrowser control in C #

Source: Internet
Author: User
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.

Related Article

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.