views:

396

answers:

2

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

+2  A: 

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.

Austin Salonen
A: 

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.

Jamie Altizer
Great, I didn't knew about the StartPosition Property. I want to use forms, because I don't just want to make a drop down menu, but a new approach.I want the cursor to be in the center of the menu, surrounded by little pictures of the controls. If you hover over one, it shows its name/function and by click enlarges it, so you can set any kind of value in the menu. thanks, :)Greg the Mad
Gregor A. Lamche