Enabling "Open In New Tab" item in WebBrowser's context menu? - c#

Is it possible to enable the "Open In New Tab" context menu item in a WebBrowser? Then I'll figure out how to handle it, but first I need to make it at least look enabled.

The WebBrowser control does not support multi-tab navigation. You'll have to create your own tabs (for example, using the TabControl control) which would contain instances of WebBrowser. There are great explanations on how it could be implemented here, there and there.
Then, you'll need to customize the context menu of your WebBrowser by adding the "Open In New Tab" action. That action will trigger your own implementation of multi-tab navigation. To customize the context menu, check this article: How to customize the WebBrowser context menu in C# WebBrowser Customization.

Related

How to prevent title bar from greyed out upon opening another form?

I am working on a custom context menu in an open-source text editor project I found on the internet. The custom context menu is made out of a Form. The problem is when I open the custom context menu, the text editor(main form) lost focus(becomes gray). I want it to look like this when the context menu opens, but not this. I have tried some solutions but they didn't work:
Solution 1: Caused the custom context menu to be on the back of the text editor once opened. It then stopped the custom context menu from working properly.
Solution 2: Caused my program to be crashed so it automatically closed.
Solution 3: I tried using either Control.Focus() or Control.Activate() to have focus on the text editor when invoking the custom context menu, but still didn't work.
Are there any other solutions I could try or am I missing something here?
Link(Head to: Branch -> v2.01) to the custom context menu project that I am working on. Please note that I have made it so that Control Key(CTRL) + Right mouse button(RMB) to invoke the custom context menu.
I am not sure whether this is conventionally the correct way to do it, but it works for me.
However, another problem it poses is that the context menu item functions cannot be executed. It can be clicked but then the nothing happens.
//activated event handler for the context menu
private void ContextMenu_Activated(object sender, EventArgs e)
{
//solution A
this.Activate(); //gives the main form the focus
//solution B
//this.Focus(); //gives the main form the focus
contextMenuObj.Visible = true; //forces the context menu to be displayed
//to maintain highlighted text in textbox in main form
richTextBox1.HideSelection = false;
//reset default flag once custom context menu opens
ctrlIsDown = false;
rmbIsUp = false;
}
This way, the main form is not greyed out when the context menu is displayed.

How to disable context menu in CefSharp chromium browser

How to disable context menu in cef sharp chromium browser and replace a new custom context menu that consists of only buttons
You implement the IContextMenuHandler interface, and then in IContextMenuHandler.OnBeforeContextMenu you call model.Clear();. Then you have to set your ChromiumWebBrowser's MenuHandler property to an instance of your implementation. From the code doc on that method (model.Clear()):
Remove all menu items. Can be used to disable the context menu.

WPF Richtextbox Default Context Menu

I have a custom RichTextBox control that inherits from WPF's RichTextBox. I want to add the option "Add to dictionary" to the default context menu.
I've scoured the net for tips on accessing the Default context menu of WPF's RichTextBox but can't find anything. I plan on using the solution Adding menu item to default context menu but I would like to reuse as much of .NET's code and logic before creating my own context menu.
So far, my attempts have only resulted with the default context menu being replaced. The closest I've gotten to adjusting the context menu is when I overrided OnContextMenuOpening method. However, it consistently states the ContextMenu is null.
How do I get access to the default context menu and add my desired option?
RichTextBox.ContextMenu is null whenever I examine it, even though the default context menu shows up. If I set the ContextMenu with a new ContextMenu, it replaces the existing context menu with a blank menu.
public class CustomRTB : RichTextBox
{
protected override void OnContextMenuOpening(ContextMenuEventArgs e)
{
this.ContextMenu = new ContextMenu();
}
}

c# simulate click in context menu

So my question is:
I got an Windows Forms application in C# and an webBrowser control in this application. When you for example right-click on a video in youtube, a context menu shows up. Now, is it possible to programmatically rightclick in the webBrowser control an then, again programmatically, click a specific entry in that context menu?
Yes it is, but you always have to start from the same pixel, or better said an actual pixel range, so you can be sure that the clicked result will be the required one. Also you cant click an item by specifying its text, you must do everything programatticaly, from the graphics point of view(just work on the X - Y Axis since its only 2 dimensional). That is the way most web bots are made for various purposes.
Do you really have to simulate a click of the context menu or is just having the desired action good enough? If so than you can just get the item from the ContextMenu.Items list and assuming it a button raise its Click event. If you do need to at least show the context menu while do this you can call the ContextMenu.Show event. This all assumes that the contextmenu for your WebBrowser control is public (not some third party inherited control that hides it or something).

WPF/C# Add new style pop up form

Quick question: I have a very busy form going on that I have developed for information about say book records.
I want to design an 'add new book form' that is essentially a pop up to input the info. What is the best way to do this? Use a Usercontrol that is called on a button click or menu click? an entire new form?
Have seen this type of functionality, but never designed it in a pop up have just had user input info on the actual form - and it can get very busy.
Thanks for any help. Cheers!
I'd follow a common UI idiom. Which is, from a menu choose "new". This would popup a modal dialog to accept information about the new book form. I'd use the "Popup" control for this dialog. Within this Popup control, I'd embed the actual input dialog which is implemented as a user control.
The popup control is part of the .Net framework. If you can't see the control in the VS2008 designer, then you can still use it by typing the Popup element directly in the text view of the .xaml file.

Categories