Simple case of winform interaction with html, winform Interaction

Source: Internet
Author: User

Simple case of winform interaction with html, winform Interaction

This article mainly records how winform interacts with information in html files, that is, loading the html interface in winform to make mutual calls.

1. Create a winform project. To load html in winform, you need a webBrowser control.

2. Create a new HTML page named "“test.htm ".

3. c # code:

// To enable the webpage to interact with winform, set the accessibility of com to true [System. security. permissions. permissionSet (System. security. permissions. securityAction. demand, Name = "FullTrust")] [System. runtime. interopServices. comVisibleAttribute (true)] public void Hello () {MessageBox. show ("OK, html function in calling wf");} private void Form1_Load (object sender, EventArgs e) {this. webBrowser1.ObjectForScripting = this; string path = Application. startupPath + @ "\ test.htm"; // MessageBox. show (path); // this. webBrowser1.Navigate (path); this. webBrowser1.Url = new System. uri (path, System. uriKind. absolute );}

 

4.html code:

<Html> 

 

5. Result: The following code loads html in winform and calls the information in c # In js.


 

6. For convenience, the js function in html is called directly in winform. Key points: this. webBrowser1.Document. InvokeScript ("js function name", parameter ");

 

7. c # code: directly drag a button control to the page.

 

private void button1_Click(object sender, EventArgs e){    this.webBrowser1.Document.InvokeScript("WfToHtml");}

 

8. js code:

<Script type = "text/javascript"> function WfToHtml () {alert ("wf calls js functions in html") ;}</script>

 

9. Results:

For beginners, the content is relatively simple. Prepare to load another swf, haha...

 


Who uses WINFORM to interact with the WEB?

Use webservice

Html form Data Interaction

I have a similar example here. I hope it will help you.
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"
"Www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<META http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<TITLE> Registration </TITLE>
<SCRIPT language = "JavaScript">
Function changeCity ()
{
Var province = document. myform. selProvince. value;
Var cityList = new Array ();
CityList ['shandong province '] = ['jinan', 'qingdao ', 'zibo', 'zaozhuang ', 'dongying', 'yantai ', 'weifang', 'jining ', 'tai'an ', 'weihai', 'rizhao '];
CityList ['sichuan province '] = ['chengdu', 'mianyang ', 'deyang', 'zigong ', 'neijiang', 'leshan', 'nanchong ', 'ya'an ', 'meishan ', 'garz', 'liangshan', 'luzhou '];
CityList ['hubei province '] = ['wuhan', 'yichang ', 'jingzhou', 'xiangfan ', 'huangshi', 'jingmen ', 'huanggang', 'shiyan ', 'enshi ', 'qianjiang'];

Document. myform. selCity. options. length = 0;
// Obtain the index of the province option. The ID is used here.
Var pIndex = document. myform. selProvince. value;
Var newOption1;
Document. myform. selCity. options. length = 0;
For (var j in cityList [pIndex])
{
NewOption1 = new Option (cityList [pIndex] [j], cityList [pIndex] [j]);
Document. myform. selCity. options. add (new ...... the remaining full text>

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.