/// <summary> /// Invoked when preference menu should be displayed. /// </summary> /// <param name="control">open menu on click.</param> public void AddPreferenceMenu(Control control) { System.Windows.Forms.ContextMenu cm = new System.Windows.Forms.ContextMenu(); control.Click += delegate { if (cm.MenuItems.Count > 0) { cm.MenuItems.Clear(); } JSConsoleEnable = jsConsole.consoleStatus; if (JSConsoleEnable) { cm.MenuItems.Add("Run JavaScript...", delegate { JSConsoleEnable = jsConsole.runJSConsole(JSConsoleEnable); }); } else if (!JSConsoleEnable) { cm.MenuItems.Add("Close JavaScript Console", delegate { JSConsoleEnable = jsConsole.runJSConsole(JSConsoleEnable); }); } cm.MenuItems.Add("Get HTML", delegate { RichTextBox richTextBox = new RichTextBox(); richTextBox.Dock = DockStyle.Fill; richTextBox.BackColor = Color.White; richTextBox.SelectionFont = new Font("Arial", 14); richTextBox.ReadOnly = true; richTextBox.Multiline = true; richTextBox.Text = browser.GetHTML(); richTextBox.SelectionStart = 0; Form form = new Form(); form.StartPosition = FormStartPosition.CenterParent; form.Text = "Get HTML"; form.Size = new Size(850, 600); form.Controls.Add(richTextBox); form.ShowDialog(); }); cm.MenuItems.Add("Popup Windows", delegate { browser.LoadURL("http://www.popuptest.com/"); }); cm.MenuItems.Add("Upload File", delegate { browser.LoadURL("http://www.cs.tut.fi/~jkorpela/forms/file.html#example"); }); cm.MenuItems.Add("Download File", delegate { browser.LoadURL("http://cloud.teamdev.com/downloads/dotnetbrowser/dotnetbrowser-1.8.2.zip"); }); cm.MenuItems.Add("JavaScript Dialogs", delegate { browser.LoadURL("http://www.javascripter.net/faq/alert.htm"); }); cm.MenuItems.Add("PDF Viewer", delegate { browser.LoadURL("http://www.orimi.com/pdf-test.pdf"); }); cm.MenuItems.Add("Adobe Flash", delegate { browser.LoadURL("https://helpx.adobe.com/flash-player.html"); }); cm.MenuItems.Add("Google Maps", delegate { browser.LoadURL("https://www.google.com.ua/maps"); }); cm.MenuItems.Add("HTML5 Video", delegate { browser.LoadURL("https://www.w3.org/2010/05/video/mediaevents.html"); }); cm.MenuItems.Add("Zoom In", delegate { browser.ZoomIn(); }); cm.MenuItems.Add("Zoom Out", delegate { browser.ZoomOut(); }); cm.MenuItems.Add("Actual size", delegate { browser.ZoomReset(); }); cm.MenuItems.Add("Proxy Settings", delegate { ProxyConfigForm proxyConfigForm = new ProxyConfigForm(browserView); proxyConfigForm.Show(); }); cm.MenuItems.Add("Save Web Page...", delegate { SaveWebPage(); }); cm.MenuItems.Add("Clear Cache", delegate { if (!browser.URL.Contains("http://refreshyourcache.com/en/cache-test/")) { browser.LoadURL("http://refreshyourcache.com/en/cache-test/"); InfoMessageBox.Show((Control)browserView, "Test page loaded. Press\n\"OK\" button to clear the cache", "Test Page"); } browser.CacheStorage.ClearCache(); browser.ReloadIgnoringCache(); InfoMessageBox.Show((Control)browserView, "Cache is cleared successfully", "Clear Cache"); }); //Child menu for MenuItem Preferences BrowserPreferencesMenu browserPreferencesMenu = new BrowserPreferencesMenu(browserView); cm.MenuItems.Add(browserPreferencesMenu.PreferencesItem()); //Child menu for MenuItem Execute Command BrowserExecuteCommandMenu browserExecuteCommandMenu = new BrowserExecuteCommandMenu(browserView); cm.MenuItems.Add(browserExecuteCommandMenu.ExecuteCommandItem()); cm.MenuItems.Add("Print...", delegate { PrintDialog dlgPrint = new PrintDialog(); bool print = (dlgPrint.ShowDialog(((Control)browserView).Parent) == DialogResult.OK); if (print) { browser.PrintHandler = new MyPDFPrintHandler((printSettings) => { printSettings.PrintToPDF = false; if (dlgPrint.PrinterSettings.PrintToFile || dlgPrint.PrinterSettings.PrinterName.Contains("PDF")) { string fileName = String.Empty; if (SaveToPDF(browser.Title, out fileName)) { printSettings.PrintToPDF = true; printSettings.PDFFilePath = fileName; } } else { printSettings.Copies = dlgPrint.PrinterSettings.Copies; printSettings.PrinterName = dlgPrint.PrinterSettings.PrinterName; printSettings.DuplexMode = (DuplexMode)dlgPrint.PrinterSettings.DefaultPageSettings.PrinterSettings.Duplex; printSettings.PrintToPDF = false; } return(printSettings); }); browser.Print(); } }); cm.MenuItems.Add("-"); cm.MenuItems.Add("More Features...", delegate { browser.LoadURL("http://dotnetbrowser-support.teamdev.com/documentation"); }); cm.MenuItems.Add("-"); cm.MenuItems.Add("About WinFormsDotNetBrowser Demo", delegate { AboutDemo(); }); Point p = new Point(0, 28); cm.Show(control, p); }; }
/// <summary> /// Invoked when preference menu should be displayed. /// </summary> /// <param name="control">open menu on click.</param> public void AddPreferenceMenu(Control control) { System.Windows.Controls.ContextMenu cm = new System.Windows.Controls.ContextMenu(); control.MouseDown += delegate { if (cm.Items.Count > 0) { cm.Items.Clear(); } JSConsoleEnable = jsConsole.consoleStatus; if (JSConsoleEnable) { cm.Items.Add(BuildMenuItem.Build("Run JavaScript...", true, false, delegate { JSConsoleEnable = jsConsole.runJSConsole(JSConsoleEnable); })); } else if (!JSConsoleEnable) { cm.Items.Add(BuildMenuItem.Build("Close JavaScript Console", true, false, delegate { JSConsoleEnable = jsConsole.runJSConsole(JSConsoleEnable); })); } cm.Items.Add(BuildMenuItem.Build("Get HTML", true, false, delegate { TextBox textBox = new TextBox(); textBox.IsReadOnly = true; textBox.Text = browser.GetHTML(); textBox.SelectionStart = 0; textBox.TextWrapping = TextWrapping.WrapWithOverflow; textBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; textBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; Window window = new Window(); window.Owner = Window.GetWindow((FrameworkElement)browserView); window.WindowStartupLocation = WindowStartupLocation.CenterOwner; window.Title = "Get HTML"; window.Height = 600; window.Width = 850; window.Content = textBox; window.ShowDialog(); })); cm.Items.Add(BuildMenuItem.Build("Popup Windows", true, false, delegate { browser.LoadURL("http://www.popuptest.com/"); })); cm.Items.Add(BuildMenuItem.Build("Upload File", true, false, delegate { browser.LoadURL("http://www.cs.tut.fi/~jkorpela/forms/file.html#example"); })); cm.Items.Add(BuildMenuItem.Build("Download File", true, false, delegate { browser.LoadURL("http://cloud.teamdev.com/downloads/dotnetbrowser/dotnetbrowser-1.8.2.zip"); })); cm.Items.Add(BuildMenuItem.Build("JavaScript Dialogs", true, false, delegate { browser.LoadURL("http://www.javascripter.net/faq/alert.htm"); })); cm.Items.Add(BuildMenuItem.Build("PDF Viewer", true, false, delegate { browser.LoadURL("http://www.orimi.com/pdf-test.pdf"); })); cm.Items.Add(BuildMenuItem.Build("Adobe Flash", true, false, delegate { browser.LoadURL("https://helpx.adobe.com/flash-player.html"); })); cm.Items.Add(BuildMenuItem.Build("Google Maps", true, false, delegate { browser.LoadURL("https://www.google.com.ua/maps"); })); cm.Items.Add(BuildMenuItem.Build("HTML5 Video", true, false, delegate { browser.LoadURL("https://www.w3.org/2010/05/video/mediaevents.html"); })); cm.Items.Add(BuildMenuItem.Build("Zoom In", true, false, delegate { browser.ZoomIn(); })); cm.Items.Add(BuildMenuItem.Build("Zoom Out", true, false, delegate { browser.ZoomOut(); })); cm.Items.Add(BuildMenuItem.Build("Actual size", true, false, delegate { browser.ZoomReset(); })); cm.Items.Add(BuildMenuItem.Build("Proxy Settings", true, false, delegate { ProxyConfigForm proxyConfigForm = new ProxyConfigForm(browserView); proxyConfigForm.Show(); })); cm.Items.Add(BuildMenuItem.Build("Save Web Page...", true, false, delegate { SaveWebPage(); })); cm.Items.Add(BuildMenuItem.Build("Clear Cache", true, false, delegate { if (!browser.URL.Contains("http://refreshyourcache.com/en/cache-test/")) { browser.LoadURL("http://refreshyourcache.com/en/cache-test/"); InfoMessageBox.Show((FrameworkElement)browserView, "Test page loaded. Press\n\"OK\" to clear the cache.", "Test page"); } browser.CacheStorage.ClearCache(); browser.ReloadIgnoringCache(); InfoMessageBox.Show((FrameworkElement)browserView, "Cache is cleared successfully", "Clear Cache"); })); //Child menu for MenuItem Preferences BrowserPreferencesMenu browserPreferencesMenu = new BrowserPreferencesMenu(browserView); cm.Items.Add(browserPreferencesMenu.PreferencesItem()); //Child menu for MenuItem Execute Command BrowserExecuteCommandMenu browserExecuteCommandMenu = new BrowserExecuteCommandMenu(browserView); cm.Items.Add(browserExecuteCommandMenu.ExecuteCommandItem()); cm.Items.Add(BuildMenuItem.Build("Print...", true, false, delegate { Nullable <Boolean> print = false; PrintDialog dlgPrint = new PrintDialog(); print = dlgPrint.ShowDialog(); string printerName = dlgPrint.PrintQueue.Name; if (print == true) { browser.PrintHandler = new MyPDFPrintHandler((printSettings) => { printSettings.PrinterName = printerName; dlgPrint.UserPageRangeEnabled = true; if (printSettings.PrinterName.Contains("PDF")) { string fileName = String.Empty; if (SaveToPDF(browser.Title, out fileName)) { printSettings.PDFFilePath = fileName; printSettings.PrintToPDF = true; } } else { printSettings.PrintToPDF = false; printSettings.PaperSize = PaperSize.DEFAULT; } printSettings.PrintBackgrounds = true; return(printSettings); }); browser.Print(); } })); cm.Items.Add(new Separator()); cm.Items.Add(BuildMenuItem.Build("More Features...", true, false, delegate { browser.LoadURL("http://dotnetbrowser-support.teamdev.com/documentation"); })); cm.Items.Add(new Separator()); cm.Items.Add(BuildMenuItem.Build("About WPFDotNetBrowser Demo", true, false, delegate { AboutDemo(); })); cm.IsOpen = true; }; }