Author Topic: Context Menu for a ToolStripItem  (Read 5816 times)

0 Members and 1 Guest are viewing this topic.

Draftek

  • Guest
Context Menu for a ToolStripItem
« on: June 06, 2006, 11:42:52 AM »
VS2005 and C#:

I've written a detail viewing / insertion program that looks much like windows explorer - with the treeview to parse the directories (and company web folders) and listview for the previews.

The *Darn* users want a 'Favories' list just like Windows Explorer. No Problem I say. I create a context menu, add an item and set the ContextMenuStrip of the TreeView for the 'Add Favorite' button.
Next I need a 'Delete Favorite' context button for the Favorie pull down. That is where the problem occurs.

MenuStrips have the ContextMenuStrip property but the MenuStripMenuItem does not.

Anybody have a clue how I would add a context menu to the drop down menu item?

Should I look into Win32 calls? I have an old dll I wrote for VB pop-up menus that would probably work, I was hoping there was a c# solution.

Dave R

  • Guest
Re: Context Menu for a ToolStripItem
« Reply #1 on: June 06, 2006, 12:08:53 PM »
I know this isn't exactly what you are looking for but it may help. This came from the help file:
Code: [Select]
private void Form1_Load(object sender, System.EventArgs e)
{
    System.Windows.Forms.ContextMenu contextMenu1;
    contextMenu1 = new System.Windows.Forms.ContextMenu();
    System.Windows.Forms.MenuItem menuItem1;
    menuItem1 = new System.Windows.Forms.MenuItem();
    System.Windows.Forms.MenuItem menuItem2;
    menuItem2 = new System.Windows.Forms.MenuItem();
    System.Windows.Forms.MenuItem menuItem3;
    menuItem3 = new System.Windows.Forms.MenuItem();

    contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {menuItem1, menuItem2, menuItem3});
    menuItem1.Index = 0;
    menuItem1.Text = "MenuItem1";
    menuItem2.Index = 1;
    menuItem2.Text = "MenuItem2";
    menuItem3.Index = 2;
    menuItem3.Text = "MenuItem3";

    textBox1.ContextMenu = contextMenu1;
}

VS2005 and C#:

I've written a detail viewing / insertion program that looks much like windows explorer - with the treeview to parse the directories (and company web folders) and listview for the previews.

The *Darn* users want a 'Favories' list just like Windows Explorer. No Problem I say. I create a context menu, add an item and set the ContextMenuStrip of the TreeView for the 'Add Favorite' button.
Next I need a 'Delete Favorite' context button for the Favorie pull down. That is where the problem occurs.

MenuStrips have the ContextMenuStrip property but the MenuStripMenuItem does not.

Anybody have a clue how I would add a context menu to the drop down menu item?

Should I look into Win32 calls? I have an old dll I wrote for VB pop-up menus that would probably work, I was hoping there was a c# solution.

Draftek

  • Guest
Re: Context Menu for a ToolStripItem
« Reply #2 on: June 06, 2006, 12:15:55 PM »
Thanks Dave but the problem is the MenuStripMenuItem does not have the .ContextMenu property (your last line) which what I need to add a context menu to.

Dave R

  • Guest
Re: Context Menu for a ToolStripItem
« Reply #3 on: June 06, 2006, 12:36:27 PM »
Oops sorry  :oops:. Should have read your original post in more detail.

Thanks Dave but the problem is the MenuStripMenuItem does not have the .ContextMenu property (your last line) which what I need to add a context menu to.

Draftek

  • Guest
Re: Context Menu for a ToolStripItem
« Reply #4 on: June 06, 2006, 12:40:03 PM »
No need to be sorry. I appreciate the reply.

Draftek

  • Guest
Re: Context Menu for a ToolStripItem
« Reply #5 on: June 06, 2006, 05:42:29 PM »
Well, I have it working using a com dll I wrote in VB6.

Feels like a band-aid solution but I'll probably stick with it unless I decide to play with Win32 calls in c#.

Glenn R

  • Guest
Re: Context Menu for a ToolStripItem
« Reply #6 on: June 06, 2006, 06:36:05 PM »
Draftek,

I'm not sure if I'm reading you right: You want to display a right-click menu on an item in a pop/pulldown menu...is that it?

Draftek

  • Guest
Re: Context Menu for a ToolStripItem
« Reply #7 on: June 07, 2006, 06:40:34 AM »
That's right Glenn,
Exactly like the Favorites Menu pull down in IE.

Glenn R

  • Guest
Re: Context Menu for a ToolStripItem
« Reply #8 on: June 07, 2006, 07:08:30 AM »
Thinking off the top of my head, could you add a context menu to the form, then trap the pop-up display event (forget what it's called but the event that fires before the pop menu is displayed) then watch for a right-click event and display your context menu accordingly?

Draftek

  • Guest
Re: Context Menu for a ToolStripItem
« Reply #9 on: June 07, 2006, 08:22:21 AM »
That's kinda how the com menu works. I trap the mouse_down event, test for the button clicked and if the right button display my menu, then test to see if it's been clicked. Then I actually do my work in this event instead of the context menu click even.

If the item had the ContextMenu property I would merely have to set it to my menu. Sounds like I'm spoiled....

Here are what they look like, not too much of a difference to the user: