Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void InitializeComponent()
     {
         this.menuStrip1 = new System.Windows.Forms.MenuStrip();
         this.mnutransactions = new System.Windows.Forms.ToolStripMenuItem();
         this.mnuSales = new System.Windows.Forms.ToolStripMenuItem();
         this.mnuPurchases = new System.Windows.Forms.ToolStripMenuItem();
         this.menuStrip1.SuspendLayout();
         this.SuspendLayout();
         //
         // menuStrip1
         //
         this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
         this.mnutransactions});
         this.menuStrip1.Location = new System.Drawing.Point(0, 0);
         this.menuStrip1.Name = "menuStrip1";
         this.menuStrip1.Size = new System.Drawing.Size(284, 24);
         this.menuStrip1.TabIndex = 0;
         this.menuStrip1.Text = "menuStrip1";
         //
         // mnutransactions
         //
         this.mnutransactions.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
         this.mnuSales,
         this.mnuPurchases});
         this.mnutransactions.Name = "mnutransactions";
         this.mnutransactions.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.T)));
         this.mnutransactions.Size = new System.Drawing.Size(86, 20);
         this.mnutransactions.Text = "&Transactions";
         //
         // mnuSales
         //
         this.mnuSales.Name = "mnuSales";
         this.mnuSales.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.S)));
         this.mnuSales.Size = new System.Drawing.Size(164, 22);
         this.mnuSales.Text = "&Sales";
         this.mnuSales.Click += new System.EventHandler(this.mnuSales_Click);
         //
         // mnuPurchases
         //
         this.mnuPurchases.Name = "mnuPurchases";
         this.mnuPurchases.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.P)));
         this.mnuPurchases.Size = new System.Drawing.Size(164, 22);
         this.mnuPurchases.Text = "&Purchases";
         //
         // Menu
         //
         this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
         this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
         this.ClientSize = new System.Drawing.Size(284, 264);
         this.Controls.Add(this.menuStrip1);
         this.MainMenuStrip = this.menuStrip1;
         this.Name = "Menu";
         this.Text = "Menu";
         this.menuStrip1.ResumeLayout(false);
         this.menuStrip1.PerformLayout();
         this.ResumeLayout(false);
         this.PerformLayout();

     }

C#
namespace HP
{
    public partial class Menu : Form
    {
        public Menu()
        {
            InitializeComponent();
        }

        private void mnuSales_Click(object sender, EventArgs e)
        {

        }
    }
}
Posted
Updated 8-Mar-14 18:57pm
v2

1 solution

Your question is not very clear.

If you want to access the shortcut keys, just use alt + the menu and that should execute the menu option.

If you want to handle the click event, use a handler to catch the event and implement it yourself.
For e.g.
C#
private void menuItem1_Click(object sender, System.EventArgs e)
{
       //Do Stuff
}
 
Share this answer
 
Comments
Member 9250821 9-Mar-14 3:19am    
When I click on Sales the Sales file should be opened. What command and namespace should be used
private void menuItem1_Click(object sender, System.EventArgs e)
{
//In webapplications we use Response.Redirect("Sales.cs");
what should be used for windows applications

}
Hope I am clear
Please help
Abhinav S 9-Mar-14 3:33am    
If you are using a database, then write a query to retrieve values from the database.
If its only a report, then open the file and display it.
Member 9250821 9-Mar-14 4:50am    
private void menuItem1_Click(object sender, System.EventArgs e)
{
opendialog(Sales.cs)
}
The above command is not working
I am not using a database but unable to give command to redirect it to sales.cs
Please help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900