mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-05 03:32:37 +00:00
Merge pull request #510 from amaitland/feature/winforms-tabbed
Winforms Example Supports Tabbed Browsing This PR resolves issue #279
This commit is contained in:
+69
-205
@@ -29,24 +29,13 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BrowserForm));
|
||||
this.toolStripContainer = new System.Windows.Forms.ToolStripContainer();
|
||||
this.toolStrip2 = new System.Windows.Forms.ToolStrip();
|
||||
this.findTextBox = new System.Windows.Forms.ToolStripTextBox();
|
||||
this.findPreviousButton = new System.Windows.Forms.ToolStripButton();
|
||||
this.findNextButton = new System.Windows.Forms.ToolStripButton();
|
||||
this.findCloseButton = new System.Windows.Forms.ToolStripButton();
|
||||
this.statusLabel = new System.Windows.Forms.Label();
|
||||
this.outputLabel = new System.Windows.Forms.Label();
|
||||
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
|
||||
this.backButton = new System.Windows.Forms.ToolStripButton();
|
||||
this.forwardButton = new System.Windows.Forms.ToolStripButton();
|
||||
this.urlTextBox = new System.Windows.Forms.ToolStripTextBox();
|
||||
this.goButton = new System.Windows.Forms.ToolStripButton();
|
||||
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
|
||||
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.newTabToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.closeTabToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.printToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.showDevToolsMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.closeDevToolsMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
@@ -61,162 +50,11 @@
|
||||
this.selectAllMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.copySourceToClipBoardAsyncMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.toolStripContainer.BottomToolStripPanel.SuspendLayout();
|
||||
this.toolStripContainer.ContentPanel.SuspendLayout();
|
||||
this.toolStripContainer.TopToolStripPanel.SuspendLayout();
|
||||
this.toolStripContainer.SuspendLayout();
|
||||
this.toolStrip2.SuspendLayout();
|
||||
this.toolStrip1.SuspendLayout();
|
||||
this.browserTabControl = new System.Windows.Forms.TabControl();
|
||||
this.closeDevToolsMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// toolStripContainer
|
||||
//
|
||||
//
|
||||
// toolStripContainer.BottomToolStripPanel
|
||||
//
|
||||
this.toolStripContainer.BottomToolStripPanel.Controls.Add(this.toolStrip2);
|
||||
//
|
||||
// toolStripContainer.ContentPanel
|
||||
//
|
||||
this.toolStripContainer.ContentPanel.Controls.Add(this.statusLabel);
|
||||
this.toolStripContainer.ContentPanel.Controls.Add(this.outputLabel);
|
||||
this.toolStripContainer.ContentPanel.Size = new System.Drawing.Size(730, 416);
|
||||
this.toolStripContainer.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.toolStripContainer.LeftToolStripPanelVisible = false;
|
||||
this.toolStripContainer.Location = new System.Drawing.Point(0, 24);
|
||||
this.toolStripContainer.Name = "toolStripContainer";
|
||||
this.toolStripContainer.RightToolStripPanelVisible = false;
|
||||
this.toolStripContainer.Size = new System.Drawing.Size(730, 466);
|
||||
this.toolStripContainer.TabIndex = 0;
|
||||
this.toolStripContainer.Text = "toolStripContainer1";
|
||||
//
|
||||
// toolStripContainer.TopToolStripPanel
|
||||
//
|
||||
this.toolStripContainer.TopToolStripPanel.Controls.Add(this.toolStrip1);
|
||||
//
|
||||
// toolStrip2
|
||||
//
|
||||
this.toolStrip2.Dock = System.Windows.Forms.DockStyle.None;
|
||||
this.toolStrip2.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
|
||||
this.toolStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.findTextBox,
|
||||
this.findPreviousButton,
|
||||
this.findNextButton,
|
||||
this.findCloseButton});
|
||||
this.toolStrip2.Location = new System.Drawing.Point(3, 0);
|
||||
this.toolStrip2.Name = "toolStrip2";
|
||||
this.toolStrip2.Size = new System.Drawing.Size(205, 25);
|
||||
this.toolStrip2.TabIndex = 0;
|
||||
//
|
||||
// findTextBox
|
||||
//
|
||||
this.findTextBox.Name = "findTextBox";
|
||||
this.findTextBox.Size = new System.Drawing.Size(100, 25);
|
||||
this.findTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FindTextBoxKeyDown);
|
||||
//
|
||||
// findPreviousButton
|
||||
//
|
||||
this.findPreviousButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
|
||||
this.findPreviousButton.Image = global::CefSharp.WinForms.Example.Properties.Resources.nav_left_green;
|
||||
this.findPreviousButton.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.findPreviousButton.Name = "findPreviousButton";
|
||||
this.findPreviousButton.Size = new System.Drawing.Size(23, 22);
|
||||
this.findPreviousButton.Text = "Find Previous";
|
||||
this.findPreviousButton.Click += new System.EventHandler(this.FindPreviousButtonClick);
|
||||
//
|
||||
// findNextButton
|
||||
//
|
||||
this.findNextButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
|
||||
this.findNextButton.Image = global::CefSharp.WinForms.Example.Properties.Resources.nav_right_green;
|
||||
this.findNextButton.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.findNextButton.Name = "findNextButton";
|
||||
this.findNextButton.Size = new System.Drawing.Size(23, 22);
|
||||
this.findNextButton.Text = "Find Next";
|
||||
this.findNextButton.Click += new System.EventHandler(this.FindNextButtonClick);
|
||||
//
|
||||
// findCloseButton
|
||||
//
|
||||
this.findCloseButton.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
|
||||
this.findCloseButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
|
||||
this.findCloseButton.Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Bold);
|
||||
this.findCloseButton.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.findCloseButton.Name = "findCloseButton";
|
||||
this.findCloseButton.Size = new System.Drawing.Size(23, 22);
|
||||
this.findCloseButton.Text = "X";
|
||||
this.findCloseButton.Click += new System.EventHandler(this.FindCloseButtonClick);
|
||||
//
|
||||
// statusLabel
|
||||
//
|
||||
this.statusLabel.AutoSize = true;
|
||||
this.statusLabel.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.statusLabel.Location = new System.Drawing.Point(0, 403);
|
||||
this.statusLabel.Name = "statusLabel";
|
||||
this.statusLabel.Size = new System.Drawing.Size(0, 13);
|
||||
this.statusLabel.TabIndex = 1;
|
||||
//
|
||||
// outputLabel
|
||||
//
|
||||
this.outputLabel.AutoSize = true;
|
||||
this.outputLabel.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.outputLabel.Location = new System.Drawing.Point(0, 403);
|
||||
this.outputLabel.Name = "outputLabel";
|
||||
this.outputLabel.Size = new System.Drawing.Size(0, 13);
|
||||
this.outputLabel.TabIndex = 0;
|
||||
//
|
||||
// toolStrip1
|
||||
//
|
||||
this.toolStrip1.Dock = System.Windows.Forms.DockStyle.None;
|
||||
this.toolStrip1.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
|
||||
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.backButton,
|
||||
this.forwardButton,
|
||||
this.urlTextBox,
|
||||
this.goButton});
|
||||
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.toolStrip1.Name = "toolStrip1";
|
||||
this.toolStrip1.Padding = new System.Windows.Forms.Padding(0);
|
||||
this.toolStrip1.Size = new System.Drawing.Size(730, 25);
|
||||
this.toolStrip1.Stretch = true;
|
||||
this.toolStrip1.TabIndex = 0;
|
||||
this.toolStrip1.Layout += new System.Windows.Forms.LayoutEventHandler(this.HandleToolStripLayout);
|
||||
//
|
||||
// backButton
|
||||
//
|
||||
this.backButton.Enabled = false;
|
||||
this.backButton.Image = global::CefSharp.WinForms.Example.Properties.Resources.nav_left_green;
|
||||
this.backButton.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.backButton.Name = "backButton";
|
||||
this.backButton.Size = new System.Drawing.Size(52, 22);
|
||||
this.backButton.Text = "Back";
|
||||
this.backButton.Click += new System.EventHandler(this.BackButtonClick);
|
||||
//
|
||||
// forwardButton
|
||||
//
|
||||
this.forwardButton.Enabled = false;
|
||||
this.forwardButton.Image = global::CefSharp.WinForms.Example.Properties.Resources.nav_right_green;
|
||||
this.forwardButton.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.forwardButton.Name = "forwardButton";
|
||||
this.forwardButton.Size = new System.Drawing.Size(70, 22);
|
||||
this.forwardButton.Text = "Forward";
|
||||
this.forwardButton.Click += new System.EventHandler(this.ForwardButtonClick);
|
||||
//
|
||||
// urlTextBox
|
||||
//
|
||||
this.urlTextBox.AutoSize = false;
|
||||
this.urlTextBox.Name = "urlTextBox";
|
||||
this.urlTextBox.Size = new System.Drawing.Size(500, 25);
|
||||
this.urlTextBox.KeyUp += new System.Windows.Forms.KeyEventHandler(this.UrlTextBoxKeyUp);
|
||||
//
|
||||
// goButton
|
||||
//
|
||||
this.goButton.Image = global::CefSharp.WinForms.Example.Properties.Resources.nav_plain_green;
|
||||
this.goButton.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.goButton.Name = "goButton";
|
||||
this.goButton.Size = new System.Drawing.Size(42, 22);
|
||||
this.goButton.Text = "Go";
|
||||
this.goButton.Click += new System.EventHandler(this.GoButtonClick);
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
@@ -231,6 +69,9 @@
|
||||
// fileToolStripMenuItem
|
||||
//
|
||||
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.newTabToolStripMenuItem,
|
||||
this.closeTabToolStripMenuItem,
|
||||
this.printToolStripMenuItem,
|
||||
this.aboutToolStripMenuItem,
|
||||
this.showDevToolsMenuItem,
|
||||
this.closeDevToolsMenuItem,
|
||||
@@ -240,6 +81,27 @@
|
||||
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
|
||||
this.fileToolStripMenuItem.Text = "File";
|
||||
//
|
||||
// newTabToolStripMenuItem
|
||||
//
|
||||
this.newTabToolStripMenuItem.Name = "newTabToolStripMenuItem";
|
||||
this.newTabToolStripMenuItem.Size = new System.Drawing.Size(158, 22);
|
||||
this.newTabToolStripMenuItem.Text = "&New Tab";
|
||||
this.newTabToolStripMenuItem.Click += new System.EventHandler(this.NewTabToolStripMenuItemClick);
|
||||
//
|
||||
// closeTabToolStripMenuItem
|
||||
//
|
||||
this.closeTabToolStripMenuItem.Name = "closeTabToolStripMenuItem";
|
||||
this.closeTabToolStripMenuItem.Size = new System.Drawing.Size(158, 22);
|
||||
this.closeTabToolStripMenuItem.Text = "&Close Tab";
|
||||
this.closeTabToolStripMenuItem.Click += new System.EventHandler(this.CloseTabToolStripMenuItemClick);
|
||||
//
|
||||
// printToolStripMenuItem
|
||||
//
|
||||
this.printToolStripMenuItem.Name = "printToolStripMenuItem";
|
||||
this.printToolStripMenuItem.Size = new System.Drawing.Size(158, 22);
|
||||
this.printToolStripMenuItem.Text = "&Print";
|
||||
this.printToolStripMenuItem.Click += new System.EventHandler(this.PrintToolStripMenuItemClick);
|
||||
//
|
||||
// aboutToolStripMenuItem
|
||||
//
|
||||
this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem";
|
||||
@@ -294,92 +156,103 @@
|
||||
// undoMenuItem
|
||||
//
|
||||
this.undoMenuItem.Name = "undoMenuItem";
|
||||
this.undoMenuItem.Size = new System.Drawing.Size(122, 22);
|
||||
this.undoMenuItem.Size = new System.Drawing.Size(251, 22);
|
||||
this.undoMenuItem.Text = "Undo";
|
||||
this.undoMenuItem.Click += new System.EventHandler(this.UndoMenuItemClick);
|
||||
//
|
||||
// redoMenuItem
|
||||
//
|
||||
this.redoMenuItem.Name = "redoMenuItem";
|
||||
this.redoMenuItem.Size = new System.Drawing.Size(122, 22);
|
||||
this.redoMenuItem.Size = new System.Drawing.Size(251, 22);
|
||||
this.redoMenuItem.Text = "Redo";
|
||||
this.redoMenuItem.Click += new System.EventHandler(this.RedoMenuItemClick);
|
||||
//
|
||||
// findMenuItem
|
||||
//
|
||||
this.findMenuItem.Name = "findMenuItem";
|
||||
this.findMenuItem.Size = new System.Drawing.Size(122, 22);
|
||||
this.findMenuItem.Size = new System.Drawing.Size(251, 22);
|
||||
this.findMenuItem.Text = "Find";
|
||||
this.findMenuItem.Click += new System.EventHandler(this.FindMenuItemClick);
|
||||
//
|
||||
// toolStripMenuItem2
|
||||
//
|
||||
this.toolStripMenuItem2.Name = "toolStripMenuItem2";
|
||||
this.toolStripMenuItem2.Size = new System.Drawing.Size(119, 6);
|
||||
this.toolStripMenuItem2.Size = new System.Drawing.Size(248, 6);
|
||||
//
|
||||
// cutMenuItem
|
||||
//
|
||||
this.cutMenuItem.Name = "cutMenuItem";
|
||||
this.cutMenuItem.Size = new System.Drawing.Size(122, 22);
|
||||
this.cutMenuItem.Size = new System.Drawing.Size(251, 22);
|
||||
this.cutMenuItem.Text = "Cut";
|
||||
this.cutMenuItem.Click += new System.EventHandler(this.CutMenuItemClick);
|
||||
//
|
||||
// copyMenuItem
|
||||
//
|
||||
this.copyMenuItem.Name = "copyMenuItem";
|
||||
this.copyMenuItem.Size = new System.Drawing.Size(122, 22);
|
||||
this.copyMenuItem.Size = new System.Drawing.Size(251, 22);
|
||||
this.copyMenuItem.Text = "Copy";
|
||||
this.copyMenuItem.Click += new System.EventHandler(this.CopyMenuItemClick);
|
||||
//
|
||||
// pasteMenuItem
|
||||
//
|
||||
this.pasteMenuItem.Name = "pasteMenuItem";
|
||||
this.pasteMenuItem.Size = new System.Drawing.Size(122, 22);
|
||||
this.pasteMenuItem.Size = new System.Drawing.Size(251, 22);
|
||||
this.pasteMenuItem.Text = "Paste";
|
||||
this.pasteMenuItem.Click += new System.EventHandler(this.PasteMenuItemClick);
|
||||
//
|
||||
// deleteMenuItem
|
||||
//
|
||||
this.deleteMenuItem.Name = "deleteMenuItem";
|
||||
this.deleteMenuItem.Size = new System.Drawing.Size(122, 22);
|
||||
this.deleteMenuItem.Size = new System.Drawing.Size(251, 22);
|
||||
this.deleteMenuItem.Text = "Delete";
|
||||
this.deleteMenuItem.Click += new System.EventHandler(this.DeleteMenuItemClick);
|
||||
//
|
||||
// selectAllMenuItem
|
||||
//
|
||||
this.selectAllMenuItem.Name = "selectAllMenuItem";
|
||||
this.selectAllMenuItem.Size = new System.Drawing.Size(122, 22);
|
||||
this.selectAllMenuItem.Size = new System.Drawing.Size(251, 22);
|
||||
this.selectAllMenuItem.Text = "Select All";
|
||||
this.selectAllMenuItem.Click += new System.EventHandler(this.SelectAllMenuItemClick);
|
||||
//
|
||||
// toolStripSeparator1
|
||||
//
|
||||
this.toolStripSeparator1.Name = "toolStripSeparator1";
|
||||
this.toolStripSeparator1.Size = new System.Drawing.Size(242, 6);
|
||||
this.toolStripSeparator1.Size = new System.Drawing.Size(248, 6);
|
||||
//
|
||||
// copySourceToClipBoardAsyncMenuItem
|
||||
//
|
||||
this.copySourceToClipBoardAsyncMenuItem.Name = "copySourceToClipBoardAsyncMenuItem";
|
||||
this.copySourceToClipBoardAsyncMenuItem.Size = new System.Drawing.Size(245, 22);
|
||||
this.copySourceToClipBoardAsyncMenuItem.Size = new System.Drawing.Size(251, 22);
|
||||
this.copySourceToClipBoardAsyncMenuItem.Text = "Copy Source to Clipboard (async)";
|
||||
this.copySourceToClipBoardAsyncMenuItem.Click += new System.EventHandler(this.CopySourceToClipBoardAsyncClick);
|
||||
//
|
||||
// browserTabControl
|
||||
//
|
||||
this.browserTabControl.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.browserTabControl.Location = new System.Drawing.Point(0, 24);
|
||||
this.browserTabControl.Name = "browserTabControl";
|
||||
this.browserTabControl.SelectedIndex = 0;
|
||||
this.browserTabControl.Size = new System.Drawing.Size(730, 466);
|
||||
this.browserTabControl.TabIndex = 2;
|
||||
//
|
||||
// closeDevToolsMenuItem
|
||||
//
|
||||
this.closeDevToolsMenuItem.Name = "closeDevToolsMenuItem";
|
||||
this.closeDevToolsMenuItem.Size = new System.Drawing.Size(158, 22);
|
||||
this.closeDevToolsMenuItem.Text = "Close Dev Tools";
|
||||
this.closeDevToolsMenuItem.Click += new System.EventHandler(this.CloseDevToolsMenuItemClick);
|
||||
//
|
||||
// BrowserForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(730, 490);
|
||||
this.Controls.Add(this.toolStripContainer);
|
||||
this.Controls.Add(this.browserTabControl);
|
||||
this.Controls.Add(this.menuStrip1);
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.MainMenuStrip = this.menuStrip1;
|
||||
this.Name = "BrowserForm";
|
||||
this.Text = "BrowserForm";
|
||||
this.toolStripContainer.BottomToolStripPanel.ResumeLayout(false);
|
||||
this.toolStripContainer.BottomToolStripPanel.PerformLayout();
|
||||
this.toolStripContainer.ContentPanel.ResumeLayout(false);
|
||||
this.toolStripContainer.ContentPanel.PerformLayout();
|
||||
this.toolStripContainer.TopToolStripPanel.ResumeLayout(false);
|
||||
this.toolStripContainer.TopToolStripPanel.PerformLayout();
|
||||
this.toolStripContainer.ResumeLayout(false);
|
||||
this.toolStripContainer.PerformLayout();
|
||||
this.toolStrip2.ResumeLayout(false);
|
||||
this.toolStrip2.PerformLayout();
|
||||
this.toolStrip1.ResumeLayout(false);
|
||||
this.toolStrip1.PerformLayout();
|
||||
this.menuStrip1.ResumeLayout(false);
|
||||
this.menuStrip1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
@@ -389,17 +262,10 @@
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.ToolStripContainer toolStripContainer;
|
||||
private System.Windows.Forms.ToolStrip toolStrip1;
|
||||
private System.Windows.Forms.ToolStripButton backButton;
|
||||
private System.Windows.Forms.ToolStripButton forwardButton;
|
||||
private System.Windows.Forms.ToolStripTextBox urlTextBox;
|
||||
private System.Windows.Forms.ToolStripButton goButton;
|
||||
private System.Windows.Forms.MenuStrip menuStrip1;
|
||||
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
|
||||
private System.Windows.Forms.Label outputLabel;
|
||||
private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem undoMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem redoMenuItem;
|
||||
@@ -410,17 +276,15 @@
|
||||
private System.Windows.Forms.ToolStripMenuItem selectAllMenuItem;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
|
||||
private System.Windows.Forms.ToolStripMenuItem showDevToolsMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem closeDevToolsMenuItem;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem3;
|
||||
private System.Windows.Forms.ToolStrip toolStrip2;
|
||||
private System.Windows.Forms.ToolStripButton findPreviousButton;
|
||||
private System.Windows.Forms.ToolStripTextBox findTextBox;
|
||||
private System.Windows.Forms.ToolStripButton findNextButton;
|
||||
private System.Windows.Forms.ToolStripButton findCloseButton;
|
||||
private System.Windows.Forms.ToolStripMenuItem findMenuItem;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
|
||||
private System.Windows.Forms.ToolStripMenuItem copySourceToClipBoardAsyncMenuItem;
|
||||
private System.Windows.Forms.Label statusLabel;
|
||||
private System.Windows.Forms.TabControl browserTabControl;
|
||||
private System.Windows.Forms.ToolStripMenuItem newTabToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem closeTabToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem printToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem closeDevToolsMenuItem;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,253 +2,224 @@
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
using CefSharp.Example;
|
||||
using CefSharp.WinForms.Example.Controls;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using CefSharp.Example;
|
||||
|
||||
namespace CefSharp.WinForms.Example
|
||||
{
|
||||
public partial class BrowserForm : Form
|
||||
{
|
||||
private readonly ChromiumWebBrowser browser;
|
||||
private const string DefaultUrlForAddedTabs = "https://www.google.com";
|
||||
|
||||
public BrowserForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Load += BrowserFormLoad;
|
||||
|
||||
Text = "CefSharp";
|
||||
WindowState = FormWindowState.Maximized;
|
||||
|
||||
browser = new ChromiumWebBrowser(CefExample.DefaultUrl)
|
||||
AddTab(CefExample.DefaultUrl);
|
||||
}
|
||||
|
||||
private void AddTab(string url, int? insertIndex = null)
|
||||
{
|
||||
browserTabControl.SuspendLayout();
|
||||
|
||||
var browser = new BrowserTabUserControl(url)
|
||||
{
|
||||
Dock = DockStyle.Fill,
|
||||
};
|
||||
toolStripContainer.ContentPanel.Controls.Add(browser);
|
||||
|
||||
browser.DownloadHandler = new DownloadHandler();
|
||||
browser.MenuHandler = new MenuHandler();
|
||||
browser.NavStateChanged += OnBrowserNavStateChanged;
|
||||
browser.ConsoleMessage += OnBrowserConsoleMessage;
|
||||
browser.StatusMessage += OnBrowserStatusMessage;
|
||||
browser.TitleChanged += OnBrowserTitleChanged;
|
||||
browser.AddressChanged += OnBrowserAddressChanged;
|
||||
|
||||
var version = String.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion);
|
||||
DisplayOutput(version);
|
||||
}
|
||||
|
||||
private void BrowserFormLoad(object sender, EventArgs e)
|
||||
{
|
||||
ToggleBottomToolStrip();
|
||||
}
|
||||
|
||||
private void OnBrowserConsoleMessage(object sender, ConsoleMessageEventArgs args)
|
||||
{
|
||||
DisplayOutput(string.Format("Line: {0}, Source: {1}, Message: {2}", args.Line, args.Source, args.Message));
|
||||
}
|
||||
|
||||
private void OnBrowserStatusMessage(object sender, StatusMessageEventArgs args)
|
||||
{
|
||||
this.InvokeOnUiThreadIfRequired(() => statusLabel.Text = args.Value);
|
||||
}
|
||||
|
||||
private void OnBrowserNavStateChanged(object sender, NavStateChangedEventArgs args)
|
||||
{
|
||||
SetCanGoBack(args.CanGoBack);
|
||||
SetCanGoForward(args.CanGoForward);
|
||||
|
||||
this.InvokeOnUiThreadIfRequired(() => SetIsLoading(!args.CanReload));
|
||||
}
|
||||
|
||||
private void OnBrowserTitleChanged(object sender, TitleChangedEventArgs args)
|
||||
{
|
||||
this.InvokeOnUiThreadIfRequired(() => Text = args.Title);
|
||||
}
|
||||
|
||||
private void OnBrowserAddressChanged(object sender, AddressChangedEventArgs args)
|
||||
{
|
||||
this.InvokeOnUiThreadIfRequired(() => urlTextBox.Text = args.Address);
|
||||
}
|
||||
|
||||
private void SetCanGoBack(bool canGoBack)
|
||||
{
|
||||
this.InvokeOnUiThreadIfRequired(() => backButton.Enabled = canGoBack);
|
||||
}
|
||||
|
||||
private void SetCanGoForward(bool canGoForward)
|
||||
{
|
||||
this.InvokeOnUiThreadIfRequired(() => forwardButton.Enabled = canGoForward);
|
||||
}
|
||||
|
||||
private void SetIsLoading(bool isLoading)
|
||||
{
|
||||
goButton.Text = isLoading ?
|
||||
"Stop" :
|
||||
"Go";
|
||||
goButton.Image = isLoading ?
|
||||
Properties.Resources.nav_plain_red :
|
||||
Properties.Resources.nav_plain_green;
|
||||
|
||||
HandleToolStripLayout();
|
||||
}
|
||||
|
||||
public void ExecuteScript(string script)
|
||||
{
|
||||
browser.ExecuteScriptAsync(script);
|
||||
}
|
||||
|
||||
public object EvaluateScript(string script)
|
||||
{
|
||||
return browser.EvaluateScript(script);
|
||||
}
|
||||
|
||||
public void DisplayOutput(string output)
|
||||
{
|
||||
this.InvokeOnUiThreadIfRequired(() => outputLabel.Text = output);
|
||||
}
|
||||
|
||||
private void HandleToolStripLayout(object sender, LayoutEventArgs e)
|
||||
{
|
||||
HandleToolStripLayout();
|
||||
}
|
||||
|
||||
private void HandleToolStripLayout()
|
||||
{
|
||||
var width = toolStrip1.Width;
|
||||
foreach (ToolStripItem item in toolStrip1.Items)
|
||||
var tabPage = new TabPage(url)
|
||||
{
|
||||
if (item != urlTextBox)
|
||||
{
|
||||
width -= item.Width - item.Margin.Horizontal;
|
||||
}
|
||||
Dock = DockStyle.Fill
|
||||
};
|
||||
|
||||
tabPage.Controls.Add(browser);
|
||||
|
||||
if (insertIndex == null)
|
||||
{
|
||||
browserTabControl.TabPages.Add(tabPage);
|
||||
}
|
||||
urlTextBox.Width = Math.Max(0, width - urlTextBox.Margin.Horizontal - 18);
|
||||
else
|
||||
{
|
||||
browserTabControl.TabPages.Insert(insertIndex.Value, tabPage);
|
||||
}
|
||||
|
||||
//Make newly created tab active
|
||||
browserTabControl.SelectedTab = tabPage;
|
||||
|
||||
browserTabControl.ResumeLayout(true);
|
||||
}
|
||||
|
||||
private void ExitMenuItemClick(object sender, EventArgs e)
|
||||
{
|
||||
browser.Dispose();
|
||||
ExitApplication();
|
||||
}
|
||||
|
||||
private void ExitApplication()
|
||||
{
|
||||
Cef.Shutdown();
|
||||
Close();
|
||||
}
|
||||
|
||||
private void GoButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
LoadUrl(urlTextBox.Text);
|
||||
}
|
||||
|
||||
private void BackButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
browser.Back();
|
||||
}
|
||||
|
||||
private void ForwardButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
browser.Forward();
|
||||
}
|
||||
|
||||
private void UrlTextBoxKeyUp(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode != Keys.Enter)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LoadUrl(urlTextBox.Text);
|
||||
}
|
||||
|
||||
private void LoadUrl(string url)
|
||||
{
|
||||
if (Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute))
|
||||
{
|
||||
browser.Load(url);
|
||||
}
|
||||
}
|
||||
|
||||
private void AboutToolStripMenuItemClick(object sender, EventArgs e)
|
||||
{
|
||||
new AboutBox().ShowDialog();
|
||||
}
|
||||
|
||||
private void FindCloseButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
ToggleBottomToolStrip();
|
||||
}
|
||||
|
||||
private void FindMenuItemClick(object sender, EventArgs e)
|
||||
{
|
||||
ToggleBottomToolStrip();
|
||||
}
|
||||
|
||||
private void ToggleBottomToolStrip()
|
||||
{
|
||||
if (toolStripContainer.BottomToolStripPanelVisible)
|
||||
var control = GetCurrentTabControl();
|
||||
if (control != null)
|
||||
{
|
||||
browser.StopFinding(true);
|
||||
toolStripContainer.BottomToolStripPanelVisible = false;
|
||||
control.ShowFind();
|
||||
}
|
||||
else
|
||||
{
|
||||
toolStripContainer.BottomToolStripPanelVisible = true;
|
||||
findTextBox.Focus();
|
||||
}
|
||||
}
|
||||
|
||||
private void FindNextButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
Find(true);
|
||||
}
|
||||
|
||||
private void FindPreviousButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
Find(false);
|
||||
}
|
||||
|
||||
private void Find(bool next)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(findTextBox.Text))
|
||||
{
|
||||
browser.Find(0, findTextBox.Text, next, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void FindTextBoxKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode != Keys.Enter)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Find(true);
|
||||
}
|
||||
|
||||
private void CopySourceToClipBoardAsyncClick(object sender, EventArgs e)
|
||||
{
|
||||
var task = browser.GetSourceAsync();
|
||||
|
||||
task.ContinueWith(t =>
|
||||
var control = GetCurrentTabControl();
|
||||
if (control != null)
|
||||
{
|
||||
if (!t.IsFaulted)
|
||||
{
|
||||
Clipboard.SetText(t.Result);
|
||||
DisplayOutput("HTML Source copied to clipboard");
|
||||
}
|
||||
},
|
||||
TaskScheduler.FromCurrentSynchronizationContext());
|
||||
control.CopySourceToClipBoardAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private BrowserTabUserControl GetCurrentTabControl()
|
||||
{
|
||||
if (browserTabControl.SelectedIndex == -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var tabPage = browserTabControl.Controls[browserTabControl.SelectedIndex];
|
||||
var control = (BrowserTabUserControl)tabPage.Controls[0];
|
||||
|
||||
return control;
|
||||
}
|
||||
|
||||
private void NewTabToolStripMenuItemClick(object sender, EventArgs e)
|
||||
{
|
||||
AddTab(DefaultUrlForAddedTabs);
|
||||
}
|
||||
|
||||
private void CloseTabToolStripMenuItemClick(object sender, EventArgs e)
|
||||
{
|
||||
if(browserTabControl.Controls.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var currentIndex = browserTabControl.SelectedIndex;
|
||||
|
||||
var tabPage = browserTabControl.Controls[currentIndex];
|
||||
|
||||
var control = GetCurrentTabControl();
|
||||
if (control != null)
|
||||
{
|
||||
control.Dispose();
|
||||
}
|
||||
|
||||
browserTabControl.Controls.Remove(tabPage);
|
||||
|
||||
browserTabControl.SelectedIndex = currentIndex - 1;
|
||||
|
||||
if (browserTabControl.Controls.Count == 0)
|
||||
{
|
||||
ExitApplication();
|
||||
}
|
||||
}
|
||||
|
||||
private void UndoMenuItemClick(object sender, EventArgs e)
|
||||
{
|
||||
var control = GetCurrentTabControl();
|
||||
if (control != null)
|
||||
{
|
||||
control.Browser.Undo();
|
||||
}
|
||||
}
|
||||
|
||||
private void RedoMenuItemClick(object sender, EventArgs e)
|
||||
{
|
||||
var control = GetCurrentTabControl();
|
||||
if (control != null)
|
||||
{
|
||||
control.Browser.Redo();
|
||||
}
|
||||
}
|
||||
|
||||
private void CutMenuItemClick(object sender, EventArgs e)
|
||||
{
|
||||
var control = GetCurrentTabControl();
|
||||
if (control != null)
|
||||
{
|
||||
control.Browser.Cut();
|
||||
}
|
||||
}
|
||||
|
||||
private void CopyMenuItemClick(object sender, EventArgs e)
|
||||
{
|
||||
var control = GetCurrentTabControl();
|
||||
if (control != null)
|
||||
{
|
||||
control.Browser.Copy();
|
||||
}
|
||||
}
|
||||
|
||||
private void PasteMenuItemClick(object sender, EventArgs e)
|
||||
{
|
||||
var control = GetCurrentTabControl();
|
||||
if (control != null)
|
||||
{
|
||||
control.Browser.Paste();
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteMenuItemClick(object sender, EventArgs e)
|
||||
{
|
||||
var control = GetCurrentTabControl();
|
||||
if (control != null)
|
||||
{
|
||||
control.Browser.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectAllMenuItemClick(object sender, EventArgs e)
|
||||
{
|
||||
var control = GetCurrentTabControl();
|
||||
if (control != null)
|
||||
{
|
||||
control.Browser.SelectAll();
|
||||
}
|
||||
}
|
||||
|
||||
private void PrintToolStripMenuItemClick(object sender, EventArgs e)
|
||||
{
|
||||
var control = GetCurrentTabControl();
|
||||
if (control != null)
|
||||
{
|
||||
control.Browser.Print();
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowDevToolsMenuItemClick(object sender, EventArgs e)
|
||||
{
|
||||
browser.ShowDevTools();
|
||||
var control = GetCurrentTabControl();
|
||||
if (control != null)
|
||||
{
|
||||
control.Browser.ShowDevTools();
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseDevToolsMenuItemClick(object sender, EventArgs e)
|
||||
{
|
||||
browser.CloseDevTools();
|
||||
var control = GetCurrentTabControl();
|
||||
if (control != null)
|
||||
{
|
||||
control.Browser.CloseDevTools();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,12 +117,6 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="toolStrip2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>237, 17</value>
|
||||
</metadata>
|
||||
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>122, 17</value>
|
||||
</metadata>
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
namespace CefSharp.WinForms.Example
|
||||
{
|
||||
partial class BrowserTabUserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.toolStrip2 = new System.Windows.Forms.ToolStrip();
|
||||
this.findTextBox = new System.Windows.Forms.ToolStripTextBox();
|
||||
this.findPreviousButton = new System.Windows.Forms.ToolStripButton();
|
||||
this.findNextButton = new System.Windows.Forms.ToolStripButton();
|
||||
this.findCloseButton = new System.Windows.Forms.ToolStripButton();
|
||||
this.statusLabel = new System.Windows.Forms.Label();
|
||||
this.outputLabel = new System.Windows.Forms.Label();
|
||||
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
|
||||
this.backButton = new System.Windows.Forms.ToolStripButton();
|
||||
this.forwardButton = new System.Windows.Forms.ToolStripButton();
|
||||
this.urlTextBox = new System.Windows.Forms.ToolStripTextBox();
|
||||
this.goButton = new System.Windows.Forms.ToolStripButton();
|
||||
this.browserPanel = new System.Windows.Forms.Panel();
|
||||
this.toolStrip2.SuspendLayout();
|
||||
this.toolStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// toolStrip2
|
||||
//
|
||||
this.toolStrip2.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.toolStrip2.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
|
||||
this.toolStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.findTextBox,
|
||||
this.findPreviousButton,
|
||||
this.findNextButton,
|
||||
this.findCloseButton});
|
||||
this.toolStrip2.Location = new System.Drawing.Point(0, 465);
|
||||
this.toolStrip2.Name = "toolStrip2";
|
||||
this.toolStrip2.Size = new System.Drawing.Size(730, 25);
|
||||
this.toolStrip2.TabIndex = 0;
|
||||
this.toolStrip2.Visible = false;
|
||||
//
|
||||
// findTextBox
|
||||
//
|
||||
this.findTextBox.Name = "findTextBox";
|
||||
this.findTextBox.Size = new System.Drawing.Size(100, 25);
|
||||
this.findTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FindTextBoxKeyDown);
|
||||
//
|
||||
// findPreviousButton
|
||||
//
|
||||
this.findPreviousButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
|
||||
this.findPreviousButton.Image = global::CefSharp.WinForms.Example.Properties.Resources.nav_left_green;
|
||||
this.findPreviousButton.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.findPreviousButton.Name = "findPreviousButton";
|
||||
this.findPreviousButton.Size = new System.Drawing.Size(23, 22);
|
||||
this.findPreviousButton.Text = "Find Previous";
|
||||
this.findPreviousButton.Click += new System.EventHandler(this.FindPreviousButtonClick);
|
||||
//
|
||||
// findNextButton
|
||||
//
|
||||
this.findNextButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
|
||||
this.findNextButton.Image = global::CefSharp.WinForms.Example.Properties.Resources.nav_right_green;
|
||||
this.findNextButton.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.findNextButton.Name = "findNextButton";
|
||||
this.findNextButton.Size = new System.Drawing.Size(23, 22);
|
||||
this.findNextButton.Text = "Find Next";
|
||||
this.findNextButton.Click += new System.EventHandler(this.FindNextButtonClick);
|
||||
//
|
||||
// findCloseButton
|
||||
//
|
||||
this.findCloseButton.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
|
||||
this.findCloseButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
|
||||
this.findCloseButton.Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Bold);
|
||||
this.findCloseButton.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.findCloseButton.Name = "findCloseButton";
|
||||
this.findCloseButton.Size = new System.Drawing.Size(23, 22);
|
||||
this.findCloseButton.Text = "X";
|
||||
this.findCloseButton.Click += new System.EventHandler(this.FindCloseButtonClick);
|
||||
//
|
||||
// statusLabel
|
||||
//
|
||||
this.statusLabel.AutoSize = true;
|
||||
this.statusLabel.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.statusLabel.Location = new System.Drawing.Point(0, 439);
|
||||
this.statusLabel.Name = "statusLabel";
|
||||
this.statusLabel.Size = new System.Drawing.Size(0, 13);
|
||||
this.statusLabel.TabIndex = 1;
|
||||
//
|
||||
// outputLabel
|
||||
//
|
||||
this.outputLabel.AutoSize = true;
|
||||
this.outputLabel.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.outputLabel.Location = new System.Drawing.Point(0, 452);
|
||||
this.outputLabel.Name = "outputLabel";
|
||||
this.outputLabel.Size = new System.Drawing.Size(0, 13);
|
||||
this.outputLabel.TabIndex = 0;
|
||||
//
|
||||
// toolStrip1
|
||||
//
|
||||
this.toolStrip1.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
|
||||
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.backButton,
|
||||
this.forwardButton,
|
||||
this.urlTextBox,
|
||||
this.goButton});
|
||||
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.toolStrip1.Name = "toolStrip1";
|
||||
this.toolStrip1.Padding = new System.Windows.Forms.Padding(0);
|
||||
this.toolStrip1.Size = new System.Drawing.Size(730, 25);
|
||||
this.toolStrip1.Stretch = true;
|
||||
this.toolStrip1.TabIndex = 0;
|
||||
this.toolStrip1.Layout += new System.Windows.Forms.LayoutEventHandler(this.HandleToolStripLayout);
|
||||
//
|
||||
// backButton
|
||||
//
|
||||
this.backButton.Enabled = false;
|
||||
this.backButton.Image = global::CefSharp.WinForms.Example.Properties.Resources.nav_left_green;
|
||||
this.backButton.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.backButton.Name = "backButton";
|
||||
this.backButton.Size = new System.Drawing.Size(52, 22);
|
||||
this.backButton.Text = "Back";
|
||||
this.backButton.Click += new System.EventHandler(this.BackButtonClick);
|
||||
//
|
||||
// forwardButton
|
||||
//
|
||||
this.forwardButton.Enabled = false;
|
||||
this.forwardButton.Image = global::CefSharp.WinForms.Example.Properties.Resources.nav_right_green;
|
||||
this.forwardButton.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.forwardButton.Name = "forwardButton";
|
||||
this.forwardButton.Size = new System.Drawing.Size(70, 22);
|
||||
this.forwardButton.Text = "Forward";
|
||||
this.forwardButton.Click += new System.EventHandler(this.ForwardButtonClick);
|
||||
//
|
||||
// urlTextBox
|
||||
//
|
||||
this.urlTextBox.AutoSize = false;
|
||||
this.urlTextBox.Name = "urlTextBox";
|
||||
this.urlTextBox.Size = new System.Drawing.Size(500, 25);
|
||||
this.urlTextBox.KeyUp += new System.Windows.Forms.KeyEventHandler(this.UrlTextBoxKeyUp);
|
||||
//
|
||||
// goButton
|
||||
//
|
||||
this.goButton.Image = global::CefSharp.WinForms.Example.Properties.Resources.nav_plain_green;
|
||||
this.goButton.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.goButton.Name = "goButton";
|
||||
this.goButton.Size = new System.Drawing.Size(42, 22);
|
||||
this.goButton.Text = "Go";
|
||||
this.goButton.Click += new System.EventHandler(this.GoButtonClick);
|
||||
//
|
||||
// browserPanel
|
||||
//
|
||||
this.browserPanel.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.browserPanel.Location = new System.Drawing.Point(0, 25);
|
||||
this.browserPanel.Name = "browserPanel";
|
||||
this.browserPanel.Size = new System.Drawing.Size(730, 414);
|
||||
this.browserPanel.TabIndex = 2;
|
||||
//
|
||||
// BrowserTabUserControl
|
||||
//
|
||||
this.Controls.Add(this.browserPanel);
|
||||
this.Controls.Add(this.toolStrip1);
|
||||
this.Controls.Add(this.statusLabel);
|
||||
this.Controls.Add(this.outputLabel);
|
||||
this.Controls.Add(this.toolStrip2);
|
||||
this.Name = "BrowserTabUserControl";
|
||||
this.Size = new System.Drawing.Size(730, 490);
|
||||
this.toolStrip2.ResumeLayout(false);
|
||||
this.toolStrip2.PerformLayout();
|
||||
this.toolStrip1.ResumeLayout(false);
|
||||
this.toolStrip1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.ToolStrip toolStrip1;
|
||||
private System.Windows.Forms.ToolStripButton backButton;
|
||||
private System.Windows.Forms.ToolStripButton forwardButton;
|
||||
private System.Windows.Forms.ToolStripTextBox urlTextBox;
|
||||
private System.Windows.Forms.ToolStripButton goButton;
|
||||
private System.Windows.Forms.Label outputLabel;
|
||||
|
||||
private System.Windows.Forms.ToolStrip toolStrip2;
|
||||
private System.Windows.Forms.ToolStripButton findPreviousButton;
|
||||
private System.Windows.Forms.ToolStripTextBox findTextBox;
|
||||
private System.Windows.Forms.ToolStripButton findNextButton;
|
||||
private System.Windows.Forms.ToolStripButton findCloseButton;
|
||||
private System.Windows.Forms.Label statusLabel;
|
||||
private System.Windows.Forms.Panel browserPanel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
using System.Threading.Tasks;
|
||||
using CefSharp.WinForms.Example.Controls;
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace CefSharp.WinForms.Example
|
||||
{
|
||||
public partial class BrowserTabUserControl : UserControl
|
||||
{
|
||||
public IWinFormsWebBrowser Browser { get; private set; }
|
||||
|
||||
public BrowserTabUserControl(string url)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
var browser = new ChromiumWebBrowser(url)
|
||||
{
|
||||
Dock = DockStyle.Fill
|
||||
};
|
||||
|
||||
browserPanel.Controls.Add(browser);
|
||||
|
||||
Browser = browser;
|
||||
|
||||
Browser.MenuHandler = new MenuHandler();
|
||||
Browser.NavStateChanged += OnBrowserNavStateChanged;
|
||||
Browser.ConsoleMessage += OnBrowserConsoleMessage;
|
||||
Browser.TitleChanged += OnBrowserTitleChanged;
|
||||
Browser.AddressChanged += OnBrowserAddressChanged;
|
||||
Browser.StatusMessage += OnBrowserStatusMessage;
|
||||
|
||||
var version = String.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion);
|
||||
DisplayOutput(version);
|
||||
|
||||
Disposed += BrowserTabUserControlDisposed;
|
||||
}
|
||||
|
||||
private void BrowserTabUserControlDisposed(object sender, EventArgs e)
|
||||
{
|
||||
Disposed -= BrowserTabUserControlDisposed;
|
||||
|
||||
Browser.NavStateChanged -= OnBrowserNavStateChanged;
|
||||
Browser.ConsoleMessage -= OnBrowserConsoleMessage;
|
||||
Browser.TitleChanged -= OnBrowserTitleChanged;
|
||||
Browser.AddressChanged -= OnBrowserAddressChanged;
|
||||
Browser.StatusMessage -= OnBrowserStatusMessage;
|
||||
|
||||
Browser.Dispose();
|
||||
}
|
||||
|
||||
private void OnBrowserConsoleMessage(object sender, ConsoleMessageEventArgs args)
|
||||
{
|
||||
DisplayOutput(string.Format("Line: {0}, Source: {1}, Message: {2}", args.Line, args.Source, args.Message));
|
||||
}
|
||||
|
||||
private void OnBrowserStatusMessage(object sender, StatusMessageEventArgs args)
|
||||
{
|
||||
this.InvokeOnUiThreadIfRequired(() => statusLabel.Text = args.Value);
|
||||
}
|
||||
|
||||
private void OnBrowserNavStateChanged(object sender, NavStateChangedEventArgs args)
|
||||
{
|
||||
SetCanGoBack(args.CanGoBack);
|
||||
SetCanGoForward(args.CanGoForward);
|
||||
|
||||
this.InvokeOnUiThreadIfRequired(() => SetIsLoading(!args.CanReload));
|
||||
}
|
||||
|
||||
private void OnBrowserTitleChanged(object sender, TitleChangedEventArgs args)
|
||||
{
|
||||
this.InvokeOnUiThreadIfRequired(() => Parent.Text = args.Title);
|
||||
}
|
||||
|
||||
private void OnBrowserAddressChanged(object sender, AddressChangedEventArgs args)
|
||||
{
|
||||
this.InvokeOnUiThreadIfRequired(() => urlTextBox.Text = args.Address);
|
||||
}
|
||||
|
||||
private void SetCanGoBack(bool canGoBack)
|
||||
{
|
||||
this.InvokeOnUiThreadIfRequired(() => backButton.Enabled = canGoBack);
|
||||
}
|
||||
|
||||
private void SetCanGoForward(bool canGoForward)
|
||||
{
|
||||
this.InvokeOnUiThreadIfRequired(() => forwardButton.Enabled = canGoForward);
|
||||
}
|
||||
|
||||
private void SetIsLoading(bool isLoading)
|
||||
{
|
||||
goButton.Text = isLoading ?
|
||||
"Stop" :
|
||||
"Go";
|
||||
goButton.Image = isLoading ?
|
||||
Properties.Resources.nav_plain_red :
|
||||
Properties.Resources.nav_plain_green;
|
||||
|
||||
HandleToolStripLayout();
|
||||
}
|
||||
|
||||
public void DisplayOutput(string output)
|
||||
{
|
||||
this.InvokeOnUiThreadIfRequired(() => outputLabel.Text = output);
|
||||
}
|
||||
|
||||
private void HandleToolStripLayout(object sender, LayoutEventArgs e)
|
||||
{
|
||||
HandleToolStripLayout();
|
||||
}
|
||||
|
||||
private void HandleToolStripLayout()
|
||||
{
|
||||
var width = toolStrip1.Width;
|
||||
foreach (ToolStripItem item in toolStrip1.Items)
|
||||
{
|
||||
if (item != urlTextBox)
|
||||
{
|
||||
width -= item.Width - item.Margin.Horizontal;
|
||||
}
|
||||
}
|
||||
urlTextBox.Width = Math.Max(0, width - urlTextBox.Margin.Horizontal - 18);
|
||||
}
|
||||
|
||||
private void GoButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
LoadUrl(urlTextBox.Text);
|
||||
}
|
||||
|
||||
private void BackButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
Browser.Back();
|
||||
}
|
||||
|
||||
private void ForwardButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
Browser.Forward();
|
||||
}
|
||||
|
||||
private void UrlTextBoxKeyUp(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode != Keys.Enter)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LoadUrl(urlTextBox.Text);
|
||||
}
|
||||
|
||||
private void LoadUrl(string url)
|
||||
{
|
||||
if (Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute))
|
||||
{
|
||||
Browser.Load(url);
|
||||
}
|
||||
}
|
||||
|
||||
public void CopySourceToClipBoardAsync()
|
||||
{
|
||||
var task = Browser.GetSourceAsync();
|
||||
|
||||
task.ContinueWith(t =>
|
||||
{
|
||||
if (!t.IsFaulted)
|
||||
{
|
||||
Clipboard.SetText(t.Result);
|
||||
DisplayOutput("HTML Source copied to clipboard");
|
||||
}
|
||||
},
|
||||
TaskScheduler.FromCurrentSynchronizationContext());
|
||||
}
|
||||
|
||||
private void ToggleBottomToolStrip()
|
||||
{
|
||||
if (toolStrip2.Visible)
|
||||
{
|
||||
Browser.StopFinding(true);
|
||||
toolStrip2.Visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
toolStrip2.Visible = true;
|
||||
findTextBox.Focus();
|
||||
}
|
||||
}
|
||||
|
||||
private void FindNextButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
Find(true);
|
||||
}
|
||||
|
||||
private void FindPreviousButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
Find(false);
|
||||
}
|
||||
|
||||
private void Find(bool next)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(findTextBox.Text))
|
||||
{
|
||||
Browser.Find(0, findTextBox.Text, next, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void FindTextBoxKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode != Keys.Enter)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Find(true);
|
||||
}
|
||||
|
||||
public void ShowFind()
|
||||
{
|
||||
ToggleBottomToolStrip();
|
||||
}
|
||||
|
||||
private void FindCloseButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
ToggleBottomToolStrip();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="toolStrip2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>122, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
@@ -62,6 +62,12 @@
|
||||
<DependentUpon>BrowserForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Controls\ControlExtensions.cs" />
|
||||
<Compile Include="BrowserTabUserControl.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BrowserTabUserControl.Designer.cs">
|
||||
<DependentUpon>BrowserTabUserControl.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="MenuHandler.cs" />
|
||||
<Compile Include="Program.cs">
|
||||
</Compile>
|
||||
@@ -81,6 +87,10 @@
|
||||
<DependentUpon>BrowserForm.cs</DependentUpon>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="BrowserTabUserControl.resx">
|
||||
<DependentUpon>BrowserTabUserControl.cs</DependentUpon>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
|
||||
@@ -184,12 +184,12 @@ namespace CefSharp
|
||||
void StopFinding(bool clearSelection);
|
||||
|
||||
/// <summary>
|
||||
/// Navigates back, check <see cref="CanGoBack"/> before calling this method.
|
||||
/// Navigates back, must check <see cref="CanGoBack"/> before calling this method.
|
||||
/// </summary>
|
||||
void Back();
|
||||
|
||||
/// <summary>
|
||||
/// Navigates forward, check <see cref="CanGoForward"/> before calling this method.
|
||||
/// Navigates forward, must check <see cref="CanGoForward"/> before calling this method.
|
||||
/// </summary>
|
||||
void Forward();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user