コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
        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);
                    }
                }
            }
        }
コード例 #3
0
        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();
                }
            }
        }
コード例 #4
0
        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);
                }
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
                }
            }
        }
コード例 #7
0
        private void mainTabControl_SelectedIndexChanged(object sender, EventArgs e)
        {
            WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage;

            if (webBrowserTabPage != null && webBrowserTabPage.Browser.Url != null)
            {
                webBrowserTabPage.Browser.Focus();
            }
        }
コード例 #8
0
        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;
            }
        }
コード例 #9
0
        private void pageSwitchToolStripSpiltButton_DropDownOpening(object sender, EventArgs e)
        {
            WebBrowserTabPage webBrowserTabPage = mainTabControl.SelectedTab as WebBrowserTabPage;

            if (webBrowserTabPage != null)
            {
                stopToolStripMenuItem.Enabled = webBrowserTabPage.IsBusy;
            }
        }
コード例 #10
0
        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;
        }
コード例 #11
0
        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);
            }
        }
コード例 #12
0
 public OptionsForm(WebBrowserTabPage webBrowserTabPage)
     : this()
 {
     try
     {
         homePageTextBox.Tag = webBrowserTabPage.Browser.Url.OriginalString;
     }
     catch
     {
         homePageTextBox.Tag = "about:blank";
     }
 }
コード例 #13
0
        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);
            }
        }
コード例 #14
0
        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";
        }
コード例 #15
0
        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;
            }
        }
コード例 #16
0
        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);
            }
        }
コード例 #17
0
        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);
                }
            }
        }
コード例 #18
0
        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;
                }
            }
        }
コード例 #19
0
        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);
                }
            }
        }
コード例 #20
0
        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);
                    }
                }
            }
        }
コード例 #21
0
        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();
            }
        }
コード例 #22
0
        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);
                }
            }
        }
コード例 #23
0
        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();
                    }
                }
            }
        }
コード例 #24
0
        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);
                }
            }
        }
コード例 #25
0
        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;
                }
                }
            }
        }
コード例 #26
0
 public AboutBox(WebBrowserTabPage webBrowserTabPage)
     : this()
 {
     _webBrowserTabPage = webBrowserTabPage;
 }