Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How To Add Items To A Context Menu Programatically (C#)

Posted on 2008-11-11
2
Medium Priority
?
1,267 Views
Last Modified: 2013-12-17
I have a context menu attached to a form with some predtermined things I added during "design time". What I want to do is get a list of all open forms, and put the form titles into a Menu Item (Form List) as sub menu items. This is how I see doing those, though the coding is definitely wrong:

//This part works fine
ToolStripMenuItem contextMenuItem;
contextMenuItem = new ToolStripMenuItem("Form List");
contextMenuItem.Click += new System.EventHandler(this.contextMenuItem_Click);
this.contextMenuStrip1.Items.Add(contextMenuItem);

//This part doesnt
foreach (Form form in Application.Openforms)
{
contextMenuStrip1.Items.Add(form.Text);
}

So if anyone can show me how to make that second part work I would greatly appreciate it. Thanks.
0
Comment
Question by:Pretzel_Jesus
  • 2
2 Comments
 
LVL 14

Accepted Solution

by:
CtrlAltDl earned 2000 total points
ID: 22932796
I think it should be something like this:

foreach (Form form in Application.Openforms)
{
      ToolStripMenuItem myToolStripMenuItem = new ToolStripMenuItem(form.Text, null, null, form.Text);
     contextMenuStrip1.Items.Add(myToolStripMenuItem);
}
0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 22932805
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question