Showing a tooltip for a MenuItem

前端 未结 6 1731
北恋
北恋 2021-01-17 11:25

I\'ve got a menu that contains, among other things, some most-recently-used file paths. The paths to these files can be long, so the text sometimes gets clipped like \"C:\\

相关标签:
6条回答
  • 2021-01-17 11:58

    There is an article on CodeProject that implements a derived version of ToolStrip with custom tool tip support. This could be useful in situations where the default tool tip support is not flexible enough. http://www.codeproject.com/Tips/376643/ToolStrip-with-custom-ToolTip

    0 讨论(0)
  • 2021-01-17 12:01

    Tooltip is set manually by:

    testToolStripMenuItem2.ToolTipText = "My tooltip text";
    

    The MenuItem can for example be part of this menu constellation: a menu strip with a menu item and a sub menu item. (This plumbing code is generated automatically for you in the code behind designer file if you use visual studio)

    MenuStrip menuStrip1;    
    ToolStripMenuItem testToolStripMenuItem; // Menu item on menu bar
    menuStrip1.Items.Add(testToolStripMenuItem);
    
    ToolStripMenuItem testToolStripMenuItem2; // Sub menu item
    testToolStripMenuItem.DropDownItems.Add(testToolStripMenuItem2)
    
    0 讨论(0)
  • 2021-01-17 12:02

    If you are creating your menu items using the System.Windows.Forms.MenuItem class you won't have a "ToolTipText" property.

    You should use the System.Windows.Forms.ToolStripMenuItem class which is new as of .Net Framework 2.0 and DOES include the "ToolTipText" property.

    You also have to remember to specify ShowItemToolTips = True on the MenuStrip control

    0 讨论(0)
  • 2021-01-17 12:05

    On the MenusTrip set "ShowItemToolTips = True" and on the ToolStripMenuItem set your ToolTipText

    yourMenuStrip.ShowItemToolTips = true;
    yourToolStripMenuItem.ToolTipText = "some txt";
    
    0 讨论(0)
  • 2021-01-17 12:13

    May be that I misunderstood you problem, but why do you need to use the Tooltip class? You can assign your text to the ToolTipText property and it will be shown to the user.

    0 讨论(0)
  • 2021-01-17 12:16

    Maybe you forgot to associate the tooltip with the control using SetToolTip.

    0 讨论(0)
提交回复
热议问题