Solved

C# - Populating a MenuStrip with pure code

Posted on 2007-04-03
8
418 Views
Last Modified: 2008-02-01
Hi guys 'n gals,

Could somebody please enlighten me in how I would create a MenuStrip in C# with pure code please? So far I have this:

menuStrip1.Items.Add("File");
menuStrip1.Items.Add("Edit");

I have no clue how to add items beneath those, and beneath those, etc...


Could somebody help me out here please?

Cheers!
0
Comment
Question by:Cyber-Drugs
  • 5
  • 3
8 Comments
 
LVL 16

Expert Comment

by:AlexNek
ID: 18847572
0
 
LVL 16

Expert Comment

by:AlexNek
ID: 18847587
Create a menu strip and loook in
private void InitializeComponent()
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18847603
AlexNek,

The link you gave was for MenuItems, rather than MenuStrip...

I didn't think of checking InitializeComponent though, shall give that a go!
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 16

Expert Comment

by:AlexNek
ID: 18849132
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18851050
AlexNek,

Sorry to be a pain, but could you give me an example, let's say I wanted to create

"File" - with "Exit" below it, how would I go about doing this?

Cheers!
0
 
LVL 16

Accepted Solution

by:
AlexNek earned 500 total points
ID: 18851198
Here you are
//from  InitializeComponent()
....
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
...
            //
            // menuStrip1
            //
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.fileToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(593, 24);
            this.menuStrip1.TabIndex = 5;
            this.menuStrip1.Text = "menuStrip1";
            //
            // fileToolStripMenuItem
            //
            this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.openToolStripMenuItem,
            this.closeToolStripMenuItem,
            this.toolStripMenuItem1,
            this.exitToolStripMenuItem});
            this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
            this.fileToolStripMenuItem.Size = new System.Drawing.Size(35, 20);
            this.fileToolStripMenuItem.Text = "&File";
            //
            // openToolStripMenuItem
            //
            this.openToolStripMenuItem.Name = "openToolStripMenuItem";
            this.openToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.openToolStripMenuItem.Text = "&Open";
            //
            // closeToolStripMenuItem
            //
            this.closeToolStripMenuItem.Name = "closeToolStripMenuItem";
            this.closeToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.closeToolStripMenuItem.Text = "&Close";
            //
            // toolStripMenuItem1
            //
            this.toolStripMenuItem1.Name = "toolStripMenuItem1";
            this.toolStripMenuItem1.Size = new System.Drawing.Size(149, 6);
            //
            // exitToolStripMenuItem
            //
            this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
            this.exitToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.exitToolStripMenuItem.Text = "E&xit";
File
  Open
  Close
----------
   Exit
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18853297
Solved, cheers for your help and patience! :o)
0
 
LVL 16

Expert Comment

by:AlexNek
ID: 18853523
Gratulation! You are welcome.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 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