Is there some way to use the Menu.AttachToWidget(...) function of a gtk menu item to attach the menu to say a Gtk.Textview and have it handle showing the menu when needed. Or is creating an event handler for ButtonPressEvent and showing the menu there the only way to do it?
Or is there a third possibility that I'm missing?
Thanks in Advance.
There is a third possibility that you are missing.
TextView.PopulatePopup is an event that TextView fires when the user right clicks within the TextView. You can handle this event and insert menu items into the existing TextView context menu, which has items for cut/copy/paste and input method. This is the preferred way of adding additional context menu items to TextView.
Links to docs:
TextView
PopulatePopupHandler
Related
I want to simulate a right click on datagrid in WPF, and a context menu pop up.
But I found that the context menu is popped up via the PopupControlService which is internal to MS and I cannot access. Now I have the datagrid instance. How can I simulate a right click on this datagrid?
Thank you all.
DataGrid.RaiseEvent(new RoutedEventArgs(ContextMenuOpeningEvent));
Have you tried it?
Or
DataGrid.RaiseEvent(new RoutedEventArgs(MouseRightButtonDownEvent));
Look here: https://timscyclingblog.wordpress.com/2012/04/05/wpf-simulate-mouse-click-in-code-behind/
And also here: Raising WPF MouseLeftButtonDownEvent event
To by-passe the problem you can create manually the context menu and show it in the code behind ?
In a user control of mine I implement a tab control that should programmatically manage tab pages. I connected the tab control with a context menu strip with the menu items "Add", "Edit", "Delete" to respectively add a new tab page, edit or delete an existing one. Initially, the tab control does not have any tab pages, and in this case the context menu strip does not appear on right mouse click; if a tab page is there, the context menu strip works as required. At that, the context menu strip is attached to the tab control itself, not to any of the tab pages.
I find this state quite illogical, and my question is whether there is any possibility to make the context menu work attached to a tab control work even if the tab control is empty?
Empty TabControl does not receive mouse events. They are passed to the underlying control.
You can do the following.
Put the TabControl inside a Panel of the same size. Assign the same context menu to this Panel. Then, when TabControl is empty, mouse events will be passed to the Panel and menu will be shown too.
How can I add an item to a contextmenustrip, as well as code the button_click action for it?
I'm making a web browser application, and I have a drop down menu of 'favorite' websites. When someone clicks a button, it adds the title of the website into the dropdown menu, but I also need it navigable to the website URL that was inputted. I have no idea how to add button click actions when I add a new item to a contextmenustrip.
Is this a WinForms application?
If so, in the Visual Studio designer, after you drag a contextMenuStrip from the boolbox, it allows you to type new entries at the contextMenuStrip (click where it says 'Type Here' to add a new item). If you are going back to an existing contextMenuStrip, you will have to make it appear by clicking on the contextMenuStrip item at the bottom of the designer.
Once you have the item, you can just double-click on it to whatever code you want to execute on the click event. (This is the default event; for other events you will have to double-click the appropriate event from the Properties pane.
I have one general context menu and for example 4 buttons and 4 textboxes - when I click on any of these buttons the context menu is opened and when I click on some items I would like to send this item to textbox, which was between button - I need to send some identificator to context menu to know which button open it and then to know where to send selected item.
How can I do that?
I am using c#
Thanks
this.ActiveControl will give you the button that has the focus. You can put the identifier in the Tag property of each button. This way, this.ActiveControl.Tag will give you the information you need.
In my C# app, I have a ListView on a Form. I want the user to be able to double-click on a section of the ListView when no items are selected in order to pop up a "New Item" dialog. The problem is that the DoubleClick event for the ListView only fires if an item is selected.
Is there a way to do this?
There is a way to do this, but you have to do some low-level drilling into the Windows machinery. It's generally not a good idea to spend a great deal of time trying to get a standard Windows control to behave in a non-standard manner.
A simpler way is to just put a "New Item" button next to your ListView. If screen real estate is an issue, you could just add an extra row at the bottom that says "{click here to add new item}", and show your dialog when the user clicks this last row.
Add an event handler for the List view's MouseDoubleClick event.
Assuming Windows Forms:
Perhaps a good workaround would be to use a ContextMenu.