Question

I feel quite limited by the default ContextMenuStrip, as it only can contain buttons, and no Controls. I was wondering that for a long time, and I already tried it, using forms, but it never really worked out.

I already have I idea on how to set the whole thing up, with events and items. The only problem I have is the paint method. When you open a ContextMenu (ContextMenuStrip) you can set its position on the mouse cursor, and it will be there, even if that means that it goes beyond the active form. (So I can't use the Controls Class as inheritance, as they can only draw themself as a part of a form. Now I thought to use the Form Class as a base for my ContextMenu, but those where placed on the screen randomly.

So what I actually need is a class (or something similar) that can draw itself, without problems, and can be placed accurately on the screen.

Any hint would be nice, thanks.

Greg the Mad

Was it helpful?

Solution

If you are looking to allow for any type of control to be displayed in a top down fashion inside of a container to be positionable... you could always make a custom control using FlowLayoutPanel. With it's properties FlowDirection=TopDown and WrapContents=False to keep a vertical approach. This will handle your "menu" basics and your new control can expose whichever events you wish from each Control. You will have to handle the logic of showing the panel and positioning with it's Location property as well.

I forgot to address the issue with drawing outside of the parent form. Notice that ContextMenus are smart and when they reach a boundary of their parent they draw away from it. You should logically be able to draw in the correct direction (Up/Down or Left/Right) from any right mouse click. Per your attempt with a Form, set StartPosition=Manual then prior to calling Show() or ShowDialog() set it's Location property respective to the X and Y parameters provided in the event args of MouseClick.

OTHER TIPS

Your first statement is false -- you can have a TextBox or a ComboBox in a ContextMenuStrip.

MSDN ToolStripComboBox
MSDN ToolStripTextBox

From the designer there is a small drop-down arrow when your mouse is in the "Type Here" box (sometimes hard to click) that will allow you to change the type.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top