I`m trying to play around with MetroFramework for C# and show a nice ToolTip when a ToolStripItem is hovered, instead of the basic/regular tooltip offered.
However, I`m unable to show it "per item" because ToolStripItem has only "Owner" control property and it will show it across all items in the toolbar.
Example:
private void toolStripButton1_MouseHover(object sender, EventArgs e)
{
var tooltip = new MetroFramework.Components.MetroToolTip();
ToolStripItem tsi = (ToolStripItem)sender;
tooltip.SetToolTip(tsi.Owner, "testing the tooltips");
}
Does anyone have a solution regarding this ? Or is it just not possible without editing the MetroFramework library ?
Your input is much appreciated.
Based on the source code of this component, its derived from the System.Windows.Forms.ToolTip thus we can handle it the same way to fulfill this requirement.
First of all, you just need one instance of the
MetroToolTipin a Form. Either use the designer to drop an instance, or create one in code and dispose of it when you close the Form.To make it works per item:
At design time, set the ToolTipText properties of the
ToolStrip/MenuStrip/ContextMenuStrip/StatusStripitems.In the constructor or
Form.Loadevent, get theToolStripItemobjects using a recursive method to subscribe to theClick,MouseHover, andMouseLeaveevents. Also, theToolStripDropDownItem.DropDownOpeningevents are needed. We'll handle them to show and hide the tooltips.Example