private void Form1_Load(object sender, EventArgs e) { webBrowser = new ChromiumWebBrowser("local://local/www/views/dashboard/Index.html", this);//ChromiumWebBrowserWindowless("local://local/www/views/dashboard/Index.html", this); webBrowser.OnCGPress += WebBrowser_KeyPress; webBrowser.Dock = DockStyle.Fill; webBrowser.Visible = true; var mainWindow = new JSObject(); mainWindow.AddFunction("doMinWindow").Execute += MinWindow; mainWindow.AddFunction("doMaxWindow").Execute += MaxWindow; mainWindow.AddFunction("doCloseWindow").Execute += CloseWindow; webBrowser.GlobalObject.Add("MainWindow", mainWindow); //BrowserHandle = webBrowser.Handle; this.Controls.Add(webBrowser); }
private void Form1_Load(object sender, EventArgs e) { webBrowser = new ChromiumWebBrowser(this); webBrowser.Dock = DockStyle.Fill; //加上这句,弹出的窗口就会有标题栏,可以关闭,否则无法操作弹出的新窗口,无法关闭... webBrowser.LifeSpanHandler.OnBeforePopup += beforePop; //webBrowser.ExecuteJavascript("alert('aaaa');"); //webBrowser.LoadHandler.OnLoadEnd += LoadHandler_OnLoadEnd; webBrowser.LoadUrl("http://www.baidu.com"); }
private void InitializeChromiumWebBrowser() { this.SuspendLayout(); this.WebBrowser = new ChromiumWebBrowser(); this.WebBrowser.BackColor = System.Drawing.Color.White; this.WebBrowser.Dock = System.Windows.Forms.DockStyle.Fill; this.WebBrowser.Location = new System.Drawing.Point(0, 0); this.WebBrowser.Name = "WebBrowser"; this.WebBrowser.RemoteCallbackInvokeMode = Chromium.WebBrowser.JSInvokeMode.Inherit; this.WebBrowser.Size = new System.Drawing.Size(1441, 605); this.WebBrowser.TabIndex = 2; this.WebBrowser.RemoteBrowserCreated += (s, e) => { remoteBrowser = e.Browser; }; this.Controls.Add(this.WebBrowser); this.ResumeLayout(false); }
internal void ClearParent() { Name = null; m_parent = null; m_browser = null; }
internal void SetBrowser(string propertyName, ChromiumWebBrowser browser) { CheckUnboundState(); Name = propertyName; m_browser = browser; }
internal FindToolbar(ChromiumWebBrowser wb) { this.wb = wb; Font = new Font("Microsoft Sans Serif", 10); SetStyle(ControlStyles.FixedWidth | ControlStyles.FixedHeight | ControlStyles.SupportsTransparentBackColor | ControlStyles.EnableNotifyMessage | ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UseTextForAccessibility | ControlStyles.Selectable , false); SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque | ControlStyles.ResizeRedraw | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick | ControlStyles.UserMouse | ControlStyles.CacheText | ControlStyles.ContainerControl , true); Visible = false; downButton.Parent = this; upButton.Parent = this; matchCaseButton.Parent = this; resultLabel.Parent = this; textBox.Parent = this; closeButton.Parent = this; textBox.Font = new Font(Font, FontStyle.Italic); textBox.Left = 10; textBox.Top = 8; textBox.Width = 200; textBox.ForeColor = Color.DimGray; textBox.TextChanged += (s, e) => { if (textBox.Text.Length == 0) { if (textBox.Font.Style != FontStyle.Italic) { textBox.Font = new Font(textBox.Font, FontStyle.Italic); } wb.BrowserHost.StopFinding(true); UpdateMatchInfo(0); } else { if (textBox.Font.Style == FontStyle.Italic) { textBox.Font = new Font(textBox.Font, FontStyle.Regular); } if (!autoSearchSuspended) { Find(true); } } }; textBox.KeyDown += (s, e) => { if (e.KeyCode == Keys.Return) { Find(e.Shift ? false : true); e.Handled = true; } }; upButton.Font = new Font(Font.FontFamily, 9); upButton.SetBounds(textBox.Left + textBox.Width - 1, textBox.Top, textBox.Height, textBox.Height); SetButtonStyle(upButton); upButton.Image = Images.ArrowUp.Create(); upButton.TextAlign = ContentAlignment.MiddleCenter; upButton.Click += (s, e) => { Find(false); }; upButton.GotFocus += (s, e) => { textBox.Focus(); }; toolTip.SetToolTip(upButton, "Goto previous match"); downButton.Font = new Font(Font.FontFamily, 9); downButton.SetBounds(upButton.Left + upButton.Width - 1, textBox.Top, textBox.Height, textBox.Height); SetButtonStyle(downButton); downButton.Image = Images.ArrowDown.Create(); downButton.TextAlign = ContentAlignment.MiddleCenter; downButton.Click += (s, e) => { Find(true); }; downButton.GotFocus += (s, e) => { textBox.Focus(); }; toolTip.SetToolTip(downButton, "Goto next match"); matchCaseButton.Text = "Match Case"; matchCaseButton.ForeColor = Color.DimGray; matchCaseButton.Left = downButton.Left + downButton.Width + 10; matchCaseButton.Top = downButton.Top; matchCaseButton.Width = 110; matchCaseButton.Height = downButton.Height; matchCaseButton.FlatStyle = FlatStyle.Flat; matchCaseButton.FlatAppearance.BorderSize = 0; matchCaseButton.BackColor = Color.Transparent; matchCaseButton.TextAlign = ContentAlignment.MiddleCenter; matchCaseButton.Click += (s, e) => { ChangeMatchCase(); }; matchCaseButton.GotFocus += (s, e) => { textBox.Focus(); }; resultLabel.ForeColor = Color.DimGray; resultLabel.Left = matchCaseButton.Left + matchCaseButton.Width + 10; resultLabel.Top = matchCaseButton.Top + 3; resultLabel.AutoSize = true; Height = textBox.Height + 12; BackColor = Color.WhiteSmoke; closeButton.Height = upButton.Height; closeButton.Width = closeButton.Height; closeButton.Left = Width - closeButton.Width - 10; closeButton.Top = upButton.Top; closeButton.BackColor = Color.Transparent; closeButton.Image = Images.Cross.Create(); closeButton.FlatStyle = FlatStyle.Flat; closeButton.FlatAppearance.BorderSize = 0; toolTip.SetToolTip(closeButton, "Close the Find Bar"); closeButton.Anchor = AnchorStyles.Top | AnchorStyles.Right; closeButton.Click += (s, e) => { Visible = false; }; closeButton.GotFocus += (s, e) => { textBox.Focus(); }; SendMessage(textBox.Handle, 0x1501, 1, "Find in page"); // Once a find toolbar is created for a browser, it is kept until the browser is destroyed. // So there is no need to unsubscribe from this event. wb.FindHandler.OnFindResult += (s, e) => { if (e.FinalUpdate && e.Identifier == lastFindId) { var count = e.Count; BeginInvoke(() => UpdateMatchInfo(count)); } }; }