4

Is it possible to add a TrackBar control to a ContextMenu? So when I right click, my ContextMenu will drop down and a TrackBar will appear as a menu item?

Icemanind
  • 47,519
  • 50
  • 171
  • 296

3 Answers3

13

If your context menu is a ContexMenuStrip, you can create an item in this way:

[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.MenuStrip | 
                                   ToolStripItemDesignerAvailability.ContextMenuStrip)]
public class TrackBarMenuItem : ToolStripControlHost
{
    private TrackBar trackBar;

    public TrackBarMenuItem():base(new TrackBar())
    {
        this.trackBar = this.Control as TrackBar;
    }

    // Add properties, events etc. you want to expose...
}

Thanks to the ToolStripItemDesignerAvailability attribute, you can even see the item in the Forms Designer, as shown in the image below:

alt text

P.S.
This solution comes from this MSDN example

digEmAll
  • 56,430
  • 9
  • 115
  • 140
0

Yes, you need to set the context menu to user draw and draw the menu items yourself. You will have to create a custom MenuItem the implementes a TrackBar

Alex Mendez
  • 5,120
  • 1
  • 25
  • 23
0

For what it's worth for anyone who stumbles across this having problems with:

Constructor on type 'System.Windows.Forms.ToolStripControlHost' not found.

The only way I got it to work was by putting the derived control in it's own file. When it is in the same file as another control it confuses the designer.

Adi Lester
  • 24,731
  • 12
  • 95
  • 110
johnb003
  • 1,821
  • 16
  • 30