private void mainToolStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage; if (webBrowserTabPage != null) { if (e.ClickedItem == backToolStripButton) { webBrowserTabPage.Browser.GoBack(); } else if (e.ClickedItem == forwardToolStripButton) { webBrowserTabPage.Browser.GoForward(); } else if (e.ClickedItem == refreshToolStripButton) { webBrowserTabPage.Browser.Reload(); } else if (e.ClickedItem == homeToolStripButton) { urlToolStripComboBox.Text = ApplicationHelper.Settings.HomePage; webBrowserTabPage.Navigate(urlToolStripComboBox.Text, true); } } }
private void toolsToolStripDropDownButton_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { ToolStripMenuItem menuItem = e.ClickedItem as ToolStripMenuItem; if (menuItem != null && menuItem.DropDownItems.Count == 0) { toolsToolStripDropDownButton.HideDropDown(); } WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage; if (webBrowserTabPage != null) { if (e.ClickedItem == optionsToolStripMenuItem) { using (OptionsForm form = new OptionsForm(webBrowserTabPage)) { form.ShowDialog(this); } } else if (e.ClickedItem == aboutToolStripMenuItem) { using (AboutBox aboutBox = new AboutBox(webBrowserTabPage)) { aboutBox.ShowDialog(this); } } } }
private void pageSwitchToolStripSpiltButton_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage; if (webBrowserTabPage != null) { if (e.ClickedItem == openToolStripMenuItem) { if (!String.IsNullOrEmpty(urlToolStripComboBox.Text)) { if (!urlToolStripComboBox.Items.Contains(urlToolStripComboBox.Text)) { urlToolStripComboBox.Items.Add(urlToolStripComboBox.Text); } webBrowserTabPage.Navigate(urlToolStripComboBox.Text, true); } } else if (e.ClickedItem == openInNewTabToolStripMenuItem) { openNewWebBrowserTabPage(mainTabControl.SelectedIndex + 1, urlToolStripComboBox.Text); } else if (e.ClickedItem == stopToolStripMenuItem) { webBrowserTabPage.Browser.Stop(); } } }
private void favoritesToolStripSpiltButton_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { ToolStripMenuItem menuItem = e.ClickedItem as ToolStripMenuItem; if (menuItem != null && menuItem.DropDownItems.Count == 0) { favoritesToolStripSpiltButton.HideDropDown(); } WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage; if (webBrowserTabPage != null) { if (e.ClickedItem == addToFavoritesToolStripMenuItem) { using (AddToFavoritesForm form = new AddToFavoritesForm(webBrowserTabPage.Title, webBrowserTabPage.Browser.Url.OriginalString)) { form.ShowDialog(this); } } else if (e.ClickedItem == organizeFavoritesToolStripMenuItem) { Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.Favorites)); } else if (e.ClickedItem.Tag != null) { urlToolStripComboBox.Text = e.ClickedItem.Tag.ToString(); webBrowserTabPage.Navigate(urlToolStripComboBox.Text, true); } } }
private void openNewWebBrowserTabPage(Int32 index, String url) { WebBrowserTabPage webBrowserTabPage = new WebBrowserTabPage("Loading..."); webBrowserTabPage.Browser.Navigating += webBrowser_IsBusyDetection; webBrowserTabPage.Browser.DocumentCompleted += webBrowser_IsBusyDetection; webBrowserTabPage.Browser.NewWindowRequest += webBrowser_NewWindowRequest; webBrowserTabPage.Browser.Navigating += webBrowser_Navigating; webBrowserTabPage.Browser.Navigated += webBrowser_Navigated; webBrowserTabPage.Browser.DocumentTitleChanged += webBrowser_DocumentTitleChanged; webBrowserTabPage.Browser.DocumentCompleted += webBrowser_DocumentCompleted; webBrowserTabPage.Browser.Error += webBrowser_Error; mainTabControl.TabPages.Insert(index, webBrowserTabPage); mainTabControl.SelectedTab = webBrowserTabPage; urlToolStripComboBox.Text = url; if (!String.IsNullOrEmpty(url)) { webBrowserTabPage.Navigate(urlToolStripComboBox.Text, false); } else { urlToolStripComboBox.Focus(); } MainForm_SizeChanged(null, EventArgs.Empty); }
private void tabControlContextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { WebBrowserTabPage webBrowserTabPage = tabControlContextMenuStrip.Tag as WebBrowserTabPage; if (webBrowserTabPage != null) { if (e.ClickedItem == closeToolStripMenuItem) { closeWebBrowserTabPage(webBrowserTabPage); } else if (e.ClickedItem == closeTabsOnTheLeftToolStripMenuItem) { Int32 webBrowserTabPageIndex = mainTabControl.TabPages.IndexOf(webBrowserTabPage); for (Int32 i = 0; i < webBrowserTabPageIndex; i++) { closeWebBrowserTabPage(mainTabControl.TabPages[0]); } } else if (e.ClickedItem == closeTabsOnTheRightToolStripMenuItem) { Int32 webBrowserTabPageIndex = mainTabControl.TabPages.IndexOf(webBrowserTabPage); for (Int32 i = mainTabControl.TabCount - 2; i > webBrowserTabPageIndex; i--) { closeWebBrowserTabPage(mainTabControl.TabPages[i]); } } else if (e.ClickedItem == closeOtherTabsToolStripMenuItem) { closeTabsOnTheRightToolStripMenuItem.PerformClick(); closeTabsOnTheLeftToolStripMenuItem.PerformClick(); } else if (e.ClickedItem == refreshToolStripMenuItem) { webBrowserTabPage.Browser.Reload(); } else if (e.ClickedItem == refreshAllToolStripMenuItem) { foreach (TabPage page in mainTabControl.TabPages) { WebBrowserTabPage tabPage = page as WebBrowserTabPage; if (tabPage != null) { tabPage.Browser.Reload(); } } } else if (e.ClickedItem == newTabToolStripMenuItem) { openNewWebBrowserTabPage(mainTabControl.TabPages.IndexOf(webBrowserTabPage) + 1, null); } else if (e.ClickedItem == repeatTabToolStripMenuItem) { openNewWebBrowserTabPage(mainTabControl.TabPages.IndexOf(webBrowserTabPage) + 1, webBrowserTabPage.Browser.Url.OriginalString); } } }
private void mainTabControl_SelectedIndexChanged(object sender, EventArgs e) { WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage; if (webBrowserTabPage != null && webBrowserTabPage.Browser.Url != null) { webBrowserTabPage.Browser.Focus(); } }
private void webBrowser_IsBusyDetection(object sender, EventArgs e) { WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage; if (webBrowserTabPage != null) { pageSwitchToolStripSpiltButton.Image = !webBrowserTabPage.IsBusy ? Resources.Forward : Resources.Stop; } }
private void pageSwitchToolStripSpiltButton_DropDownOpening(object sender, EventArgs e) { WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage; if (webBrowserTabPage != null) { stopToolStripMenuItem.Enabled = webBrowserTabPage.IsBusy; } }
private void resizeWebBrowserTabPage(WebBrowserTabPage webBrowserTabPage) { Int32 width = mainTabControl.Size.Width; String title = webBrowserTabPage.Title; Int32 titleLength = (width / 100 - mainTabControl.TabCount) * ((width / 100)); titleLength = titleLength <= 0 ? 5 : titleLength; webBrowserTabPage.Text = title.Length > titleLength?title.Substring(0, titleLength) + "..." : title; }
private void webBrowser_DocumentTitleChanged(object sender, EventArgs e) { WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage; if (webBrowserTabPage != null) { this.Text = String.Format("{0} - {1}", webBrowserTabPage.Title, this.ProductName); resizeWebBrowserTabPage(webBrowserTabPage); } }
public OptionsForm(WebBrowserTabPage webBrowserTabPage) : this() { try { homePageTextBox.Tag = webBrowserTabPage.Browser.Url.OriginalString; } catch { homePageTextBox.Tag = "about:blank"; } }
private void mainTabControl_Selecting(object sender, TabControlCancelEventArgs e) { WebBrowserTabPage webBrowserTabPage = e.TabPage as WebBrowserTabPage; if (webBrowserTabPage != null) { checkWebBrowserTabPageStatus(webBrowserTabPage, false); } else { openNewWebBrowserTabPage(mainTabControl.TabCount - 1, null); } }
private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage; if (webBrowserTabPage != null) { checkWebBrowserTabPageStatus(webBrowserTabPage, true); // Update for special pages (about:blank, etc.) this.Text = String.Format("{0} - {1}", webBrowserTabPage.Title, this.ProductName); } mainToolStripStatusLabel.Text = "Ready"; }
private void mainTabControl_MouseDoubleClick(object sender, MouseEventArgs e) { WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage; if (webBrowserTabPage != null && mainTabControl.TabCount > 2) { // Try to move to left tab if closed Int32 nextIndex = mainTabControl.SelectedIndex > 0 ? mainTabControl.SelectedIndex - 1 : 0; closeWebBrowserTabPage(webBrowserTabPage); mainTabControl.SelectedIndex = nextIndex; } }
private void webBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e) { // e.Url was incorrectly written. Sometimes it causes NullReferenceException try { mainToolStripStatusLabel.Text = String.Format("Loading {0} ...", e.Url.ToString()); } catch { } WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage; if (webBrowserTabPage != null) { checkWebBrowserTabPageStatus(webBrowserTabPage, true); } }
private void MainForm_SizeChanged(object sender, EventArgs e) { // AutoSize: urlToolStripComboBox Int32 leftX = mainToolStrip.Location.X; Int32 rightX = leftX + mainToolStrip.Size.Width; foreach (ToolStripItem item in mainToolStrip.Items) { if (item != urlToolStripComboBox) { leftX += item.Size.Width; } else { break; } } for (Int32 i = mainToolStrip.Items.Count - 1; i > 0; i--) { if (mainToolStrip.Items[i] != urlToolStripComboBox) { rightX -= mainToolStrip.Items[i].Size.Width; } else { break; } } urlToolStripComboBox.Size = new Size(rightX - leftX - 5, urlToolStripComboBox.Size.Height); // AutoSize: mainTabControl.TabPages foreach (TabPage page in mainTabControl.TabPages) { WebBrowserTabPage webBrowserTabPage = page as WebBrowserTabPage; if (webBrowserTabPage != null) { resizeWebBrowserTabPage(webBrowserTabPage); } } }
private void checkWebBrowserTabPageStatus(WebBrowserTabPage webBrowserTabPage, Boolean isMainToolStripOnly) { WebKitBrowser webBrowser = webBrowserTabPage.Controls[0] as WebKitBrowser; if (webBrowser != null) { backToolStripButton.Enabled = webBrowser.CanGoBack; forwardToolStripButton.Enabled = webBrowser.CanGoForward; historyListToolStripDropDownButton.Enabled = webBrowser.CanGoBack || webBrowser.CanGoForward; if (!isMainToolStripOnly) { this.Text = String.Format("{0} - {1}", webBrowserTabPage.Title, this.ProductName); urlToolStripComboBox.Text = (webBrowser.Url != null) ? webBrowser.Url.OriginalString : String.Empty; } } }
private void historyListToolStripDropDownButton_DropDownOpening(object sender, EventArgs e) { WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage; if (webBrowserTabPage != null) { historyListToolStripDropDownButton.DropDownItems.Clear(); foreach (KeyValuePair <String, String> pair in webBrowserTabPage.HistoryList) { historyListToolStripDropDownButton.DropDownItems.Insert(0, createURLToolStripMenuItem(pair.Value, pair.Key, Resources.Link)); ToolStripMenuItem menuItem = historyListToolStripDropDownButton.DropDownItems[0] as ToolStripMenuItem; menuItem.Checked = (menuItem.Text == webBrowserTabPage.Title); } } }
private void showShowSaveAsPageDialog() { WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage; if (webBrowserTabPage != null) { using (SaveFileDialog dlg = new SaveFileDialog()) { dlg.Filter = "HTML Files (*.html)|*.html|All Files (*.*)|*.*"; dlg.RestoreDirectory = true; if (dlg.ShowDialog(this) == DialogResult.OK) { File.WriteAllText(dlg.FileName, webBrowserTabPage.Browser.DocumentText); MessageBox.Show(this, "The current web page is saved to" + Environment.NewLine + Environment.NewLine + dlg.FileName, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
private void MainForm_DragDrop(object sender, DragEventArgs e) { WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage; if (webBrowserTabPage != null) { String[] files = e.Data.GetData(DataFormats.FileDrop) as String[]; if (files != null && files.Length > 0) { urlToolStripComboBox.Text = DataHelper.RegexCollection.UrlShortcutRegex.Match(File.ReadAllText(files[0])).Groups["URL"].Value; } else { urlToolStripComboBox.Text = e.Data.GetData(DataFormats.Text).ToString(); } openToolStripMenuItem.PerformClick(); } }
private void pageToolStripDropDownButton_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { ToolStripMenuItem menuItem = e.ClickedItem as ToolStripMenuItem; if (menuItem != null && menuItem.DropDownItems.Count == 0) { pageToolStripDropDownButton.HideDropDown(); } WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage; if (webBrowserTabPage != null) { if (e.ClickedItem == saveAsToolStripMenuItem) { showShowSaveAsPageDialog(); } else if (e.ClickedItem == printToolStripMenuItem) { webBrowserTabPage.Browser.ShowPrintDialog(); } else if (e.ClickedItem == printPreviewToolStripMenuItem) { webBrowserTabPage.Browser.ShowPrintPreviewDialog(); } else if (e.ClickedItem == pageSetupToolStripMenuItem) { webBrowserTabPage.Browser.ShowPageSetupDialog(); } else if (e.ClickedItem == viewSourceToolStripMenuItem) { String fileName = Path.GetTempFileName() + ".html"; File.WriteAllText(fileName, webBrowserTabPage.Browser.DocumentText, Encoding.UTF8); Process.Start(ApplicationHelper.Settings.SourceViewer, fileName); } } }
private void mainToolStrip_ButtonClick(object sender, EventArgs e) { WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage; if (webBrowserTabPage != null) { if (sender == favoritesToolStripSpiltButton) { addToFavoritesToolStripMenuItem.PerformClick(); } else if (sender == pageSwitchToolStripSpiltButton) { if (!webBrowserTabPage.IsBusy) { openToolStripMenuItem.PerformClick(); } else { stopToolStripMenuItem.PerformClick(); } } } }
private void historyListToolStripDropDownButton_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { ToolStripMenuItem historyToolStripMenuItem = e.ClickedItem as ToolStripMenuItem; WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage; if (historyToolStripMenuItem != null && webBrowserTabPage != null) { if (historyToolStripMenuItem.Checked) { refreshToolStripButton.PerformClick(); } else { foreach (ToolStripMenuItem item in historyListToolStripDropDownButton.DropDownItems) { item.Checked = (item == historyToolStripMenuItem); } urlToolStripComboBox.Text = historyToolStripMenuItem.Tag.ToString(); webBrowserTabPage.Navigate(urlToolStripComboBox.Text, false); } } }
private void urlToolStripComboBox_KeyPress(object sender, KeyPressEventArgs e) { WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage; if (webBrowserTabPage != null) { switch ((Int32)e.KeyChar) { case 13: { e.Handled = true; openToolStripMenuItem.PerformClick(); break; } default: { break; } } } }
public AboutBox(WebBrowserTabPage webBrowserTabPage) : this() { _webBrowserTabPage = webBrowserTabPage; }