void m_WebBrowser_JavaScriptExternalCall(object sender, JavaScriptExternalEventArgs args) { switch (args.strId) { case "FormShow": // this.Show(); //m_WebBrowser.Visible = true; base.Opacity = 100; break; case "FormClose": this.Close(); break; case "FormMinSize": this.WindowState = FormWindowState.Minimized; break; case "FormMaxSize": if (this.WindowState == FormWindowState.Normal) { this.WindowState = FormWindowState.Maximized; } else if (this.WindowState == FormWindowState.Maximized) { this.WindowState = FormWindowState.Normal; } break; case "FormNormalSize": this.WindowState = FormWindowState.Normal; break; case "FormMove": //移动窗口消息 ReleaseCapture(); SendMessage(this.Handle, Win32.WM_SYSCOMMAND, Win32.SC_MOVE + Win32.HTCAPTION, 0); break; case "FormSetTitle": //设置标题 try { JSONArray param = (JSONArray)JSONConvert.DeserializeArray(args.strArg); base.Text = param[0].ToString(); } catch { } break; case "FormSetMaxSize": //设置标题 try { JSONArray param = (JSONArray)JSONConvert.DeserializeArray(args.strArg); int width = Convert.ToInt32(param[0]); int height = Convert.ToInt32(param[1]); this.MaximumSize = new Size(width, height); } catch { } break; case "FormSetSize": try { JSONArray param = (JSONArray)JSONConvert.DeserializeArray(args.strArg); int width = Convert.ToInt32(param[0]); int height = Convert.ToInt32(param[1]); this.Width = width; this.Height = height; } catch { } break; case "FormSetMinSize": //设置标题 try { JSONArray param = (JSONArray)JSONConvert.DeserializeArray(args.strArg); int width = Convert.ToInt32(param[0]); int height = Convert.ToInt32(param[1]); this.MinimumSize = new Size(width, height); } catch { } break; case "MessageBox": try { JSONArray param = (JSONArray)JSONConvert.DeserializeArray(args.strArg); JSONObject option = (JSONObject)param[0]; DialogResult result = MessageBox.Show(option["Message"].ToString(), option["Title"].ToString(), (MessageBoxButtons)Convert.ToInt16(option["Button"]), (MessageBoxIcon)Convert.ToInt16(option["Icon"])); if (!string.IsNullOrEmpty(option["CallBack"].ToString())) { JSCall(option["CallBack"].ToString(), result.ToString()); } } catch { } break; default: break; } OnExternalCall(args); }
protected virtual void OnExternalCall(JavaScriptExternalEventArgs args) { }
void m_WebBrowser_JavaScriptExternalCall(object sender, JavaScriptExternalEventArgs args) { switch (args.strId) { case "FormShow": // this.Show(); //m_WebBrowser.Visible = true; base.Opacity = 100; break; case "FormClose": this.Close(); break; case "FormMinSize": this.WindowState = FormWindowState.Minimized; break; case "FormMaxSize": if (this.WindowState == FormWindowState.Normal) this.WindowState = FormWindowState.Maximized; else if (this.WindowState == FormWindowState.Maximized) this.WindowState = FormWindowState.Normal; break; case "FormNormalSize": this.WindowState = FormWindowState.Normal; break; case "FormMove": //移动窗口消息 ReleaseCapture(); SendMessage(this.Handle, Win32.WM_SYSCOMMAND, Win32.SC_MOVE + Win32.HTCAPTION, 0); break; case "FormSetTitle": //设置标题 try { JSONArray param = (JSONArray)JSONConvert.DeserializeArray(args.strArg); base.Text = param[0].ToString(); } catch { } break; case "FormSetMaxSize": //设置标题 try { JSONArray param = (JSONArray)JSONConvert.DeserializeArray(args.strArg); int width = Convert.ToInt32(param[0]); int height = Convert.ToInt32(param[1]); this.MaximumSize = new Size(width, height); } catch { } break; case "FormSetSize": try { JSONArray param = (JSONArray)JSONConvert.DeserializeArray(args.strArg); int width = Convert.ToInt32(param[0]); int height = Convert.ToInt32(param[1]); this.Width = width; this.Height = height; } catch { } break; case "FormSetMinSize": //设置标题 try { JSONArray param = (JSONArray)JSONConvert.DeserializeArray(args.strArg); int width = Convert.ToInt32(param[0]); int height = Convert.ToInt32(param[1]); this.MinimumSize = new Size(width, height); } catch { } break; case "MessageBox": try { JSONArray param = (JSONArray)JSONConvert.DeserializeArray(args.strArg); JSONObject option = (JSONObject)param[0]; DialogResult result = MessageBox.Show(option["Message"].ToString(), option["Title"].ToString(),(MessageBoxButtons)Convert.ToInt16(option["Button"]), (MessageBoxIcon)Convert.ToInt16(option["Icon"])); if(!string.IsNullOrEmpty(option["CallBack"].ToString())) JSCall(option["CallBack"].ToString(), result.ToString()); } catch { } break; default: break; } OnExternalCall(args); }
protected virtual void OnExternalCall(JavaScriptExternalEventArgs args) { }
void webBrowser_JavaScriptExternalCall(object sender, JavaScriptExternalEventArgs args) { MessageBox.Show("js call"); }