版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

51 lines
1.7 KiB

  1. using Microsoft.Web.WebView2.Core;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace ProductionControl
  13. {
  14. public partial class FrmWeb : Form
  15. {
  16. public FrmWeb(string subject,string subUrl,string baseUrl= "http://127.0.0.1:18082/static/index.html#/")
  17. {
  18. InitializeComponent();
  19. //this.webView1.CoreWebView2InitializationCompleted += new EventHandler<Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs>(this.WebView2InitializationCompleted);
  20. //
  21. this.Text = subject;
  22. this.webView1.Source= new Uri(baseUrl+subUrl);
  23. }
  24. private void FrmWeb_Load(object sender, EventArgs e)
  25. {
  26. }
  27. private void WebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e)
  28. {
  29. this.webView1.CoreWebView2.AddHostObjectToScript("customHost", this);
  30. }
  31. private void callJs()
  32. {
  33. //webView调用js的方法示例1
  34. //string data = JsonConvert.SerializeObject(jsonObj);
  35. //this.webView1.CoreWebView2.ExecuteScriptAsync($"calcLatLng({data})");
  36. //-----------
  37. //js调用winform的方法 对应AddHostObjectToScript方法
  38. //获取主机对象
  39. //var hostObject = window.chrome.webview.hostObjects.customHost;
  40. ////调用winform的方法
  41. //hostObject.currentTile($(this).attr("src"));
  42. }
  43. }
  44. }