From 6ed6662427d370e2d2db29be05682e615d3f7a38 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 25 Jun 2014 17:07:08 +1000 Subject: [PATCH] Re-add find to BrowserTabUserControl --- CefSharp.WinForms.Example/BrowserForm.cs | 7 +- .../BrowserTabUserControl.Designer.cs | 76 ++++++++++++++++++- .../BrowserTabUserControl.cs | 59 ++++++++++++++ .../BrowserTabUserControl.resx | 5 +- 4 files changed, 142 insertions(+), 5 deletions(-) diff --git a/CefSharp.WinForms.Example/BrowserForm.cs b/CefSharp.WinForms.Example/BrowserForm.cs index c5ef496f48..55143eb9e0 100644 --- a/CefSharp.WinForms.Example/BrowserForm.cs +++ b/CefSharp.WinForms.Example/BrowserForm.cs @@ -53,10 +53,13 @@ private void AboutToolStripMenuItemClick(object sender, EventArgs e) private void FindMenuItemClick(object sender, EventArgs e) { - + var control = GetCurrentTabControl(); + if (control != null) + { + control.ShowFind(); + } } - private void CopySourceToClipBoardAsyncClick(object sender, EventArgs e) { var control = GetCurrentTabControl(); diff --git a/CefSharp.WinForms.Example/BrowserTabUserControl.Designer.cs b/CefSharp.WinForms.Example/BrowserTabUserControl.Designer.cs index fd3c10104b..c17f5fbd5c 100644 --- a/CefSharp.WinForms.Example/BrowserTabUserControl.Designer.cs +++ b/CefSharp.WinForms.Example/BrowserTabUserControl.Designer.cs @@ -29,25 +29,36 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { 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.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.toolStripContainer.BottomToolStripPanel.SuspendLayout(); this.toolStripContainer.ContentPanel.SuspendLayout(); this.toolStripContainer.TopToolStripPanel.SuspendLayout(); this.toolStripContainer.SuspendLayout(); + this.toolStrip2.SuspendLayout(); this.toolStrip1.SuspendLayout(); this.SuspendLayout(); // // toolStripContainer // // + // toolStripContainer.BottomToolStripPanel + // + this.toolStripContainer.BottomToolStripPanel.Controls.Add(this.toolStrip2); + // // toolStripContainer.ContentPanel // this.toolStripContainer.ContentPanel.Controls.Add(this.outputLabel); - this.toolStripContainer.ContentPanel.Size = new System.Drawing.Size(730, 465); + this.toolStripContainer.ContentPanel.Size = new System.Drawing.Size(730, 440); this.toolStripContainer.Dock = System.Windows.Forms.DockStyle.Fill; this.toolStripContainer.LeftToolStripPanelVisible = false; this.toolStripContainer.Location = new System.Drawing.Point(0, 0); @@ -61,11 +72,62 @@ private void InitializeComponent() // 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); + // // outputLabel // this.outputLabel.AutoSize = true; this.outputLabel.Dock = System.Windows.Forms.DockStyle.Bottom; - this.outputLabel.Location = new System.Drawing.Point(0, 452); + this.outputLabel.Location = new System.Drawing.Point(0, 427); this.outputLabel.Name = "outputLabel"; this.outputLabel.Size = new System.Drawing.Size(0, 13); this.outputLabel.TabIndex = 0; @@ -128,12 +190,16 @@ private void InitializeComponent() this.Controls.Add(this.toolStripContainer); this.Name = "BrowserTabUserControl"; this.Size = new System.Drawing.Size(730, 490); + 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.ResumeLayout(false); @@ -150,5 +216,11 @@ private void InitializeComponent() 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; + } } \ No newline at end of file diff --git a/CefSharp.WinForms.Example/BrowserTabUserControl.cs b/CefSharp.WinForms.Example/BrowserTabUserControl.cs index 3235ce9d9b..bff62c1295 100644 --- a/CefSharp.WinForms.Example/BrowserTabUserControl.cs +++ b/CefSharp.WinForms.Example/BrowserTabUserControl.cs @@ -28,6 +28,13 @@ public BrowserTabUserControl() var version = String.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion); DisplayOutput(version); + + Load += BrowserTabUserControlLoad; + } + + private void BrowserTabUserControlLoad(object sender, EventArgs e) + { + ToggleBottomToolStrip(); } private void OnBrowserConsoleMessage(object sender, ConsoleMessageEventArgs args) @@ -145,5 +152,57 @@ public void CopySourceToClipBoardAsync() }, TaskScheduler.FromCurrentSynchronizationContext()); } + + private void ToggleBottomToolStrip() + { + if (toolStripContainer.BottomToolStripPanelVisible) + { + browser.StopFinding(true); + toolStripContainer.BottomToolStripPanelVisible = false; + } + 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); + } + + public void ShowFind() + { + ToggleBottomToolStrip(); + } + + private void FindCloseButtonClick(object sender, EventArgs e) + { + ToggleBottomToolStrip(); + } } } diff --git a/CefSharp.WinForms.Example/BrowserTabUserControl.resx b/CefSharp.WinForms.Example/BrowserTabUserControl.resx index 4a80eaa527..938d2e2895 100644 --- a/CefSharp.WinForms.Example/BrowserTabUserControl.resx +++ b/CefSharp.WinForms.Example/BrowserTabUserControl.resx @@ -117,7 +117,10 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 + + 122, 17 + \ No newline at end of file