I'm making a Web Browser, but I don't know how to add these buttons on top of its ContextMenuStrip:
A Sepator make columns for all items, but no for only one line.
Do you have any idea how to make that?
I'm making a Web Browser, but I don't know how to add these buttons on top of its ContextMenuStrip:
A Sepator make columns for all items, but no for only one line.
Do you have any idea how to make that?
Here's a custom Component, inheriting ToolStripControlHost (as the .Net's ToolStripTextBox, ToolStripComboBox etc.) that hosts a UserControl instead of a standard Control.
▶ Building a UserControl, you can add whatever other Controls to its surface and manage their actions as usual, except the UserControl's Events are exposed through the
ToolStripControlHost
derived object, so implementers don't need to know anything about the underlying hosted Control.The hosted Control's events that you want to expose are subscribed to overriding OnSubscribeControlEvents() (and of course unsubscribed to overriding OnUnsubscribeControlEvents), then raising a related or composed event that returns values as needed.
▶ This is shown in the
ToolStripControlHost
class, see thepublic event EventHandler<UserActionArgs> ButtonAction
event. This event returns a customEventArgs
object which includes properties that allow to determine the action performed by the Button clicked.When needed, the hosted Control is exposed through the ToolStripControlHost.Control property.
You can initialize an existing ContextMenuStrip (
contextMenuStrip1
, here) in the constructor of the Form that uses it:ToolStripControlHost
derived class:Custom EventArgs object:
Actions enumerator:
This is how it works:
This is the full UserControl, to ease testing:
Designer file: