国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

HTML+JavaScript+CSS結合winform開發

2019-11-08 02:02:08
字體:
來源:轉載
供稿:網友

用HTML+javaScript+CSS寫好網頁后放到webbrowser中,實現Winform開發。 如圖,先寫好網頁: 這里寫圖片描述 再寫一個自定義控件,繼承webbrowser,使用該控件時要調用InitUI方法初始化。

[PermissionSet(SecurityAction.Demand, Name = "FullTrust")] [System.Runtime.InteropServices.ComVisibleAttribute(true)] public partial class WebTool : WebBrowser { public WebTool(string htmlPath) { InitializeComponent(); } public void InitUI(string htmlPath) { string baseDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); if (System.IO.File.Exists(System.IO.Path.Combine(baseDirectory, htmlPath))) { this.ObjectForScripting = this; this.Navigate(System.IO.Path.Combine(baseDirectory, htmlPath)); } } #region ----C#執行JS腳本---- public void JsMethod(string data) { webBrowser.Document.InvokeScript("JsMethodTest", new object[] { data }); } public string JsMethod1() { return webBrowser.Document.InvokeScript("JsMethodTest1").ToString(); } #endregion }

一、JS調用c#函數 1、 加載HTML頁面的webbrowser所在的控件要設置對COM組件可訪問,如下:

[PermissionSet(SecurityAction.Demand, Name = "FullTrust")] [System.Runtime.InteropServices.ComVisibleAttribute(true)] public partial class WebTool : WebBrowser

2、 HTML頁面加載完成后要設置

this.ObjectForScripting = this;

3、 JS腳本執行window.external.functionName()來調用c#里的函數,functionName為c#中的函數名,此函數訪問權限需為public

二、C#調用JS

webBrowser.Document.InvokeScript(參數)

這里寫圖片描述

object數組為要傳給JS方法的參數


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 遂昌县| 邢台县| 广河县| 琼结县| 平湖市| 莱芜市| 太康县| 灌南县| 桓仁| 昔阳县| 于都县| 靖西县| 唐海县| 文山县| 马鞍山市| 沙湾县| 彩票| 陇川县| 永州市| 东平县| 广河县| 洮南市| 云龙县| 六安市| 墨脱县| 呼和浩特市| 岳池县| 肃宁县| 祁阳县| 霍邱县| 珲春市| 本溪市| 镇赉县| 扎囊县| 宁化县| 惠东县| 桐城市| 南川市| 宁夏| 南阳市| 河间市|