.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Creating menu strip at runtime

Posted By:krishnavenikaladi       Posted Date: March 22, 2010    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

The code snippet shows how to menu items and event handlers for menu items.
 

The code snippet shows how to menu items and event handlers for menu items.

    

 private void Form1_Load(object sender, EventArgs e)

        {   //menu is created

            MenuStrip menu1 = new MenuStrip();

            //Items for menu r created

            ToolStripMenuItem item = new ToolStripMenuItem("&File");

            item.DropDownItems.Add("&New");

            item.DropDownItems.Add("&Open",null,fileopen);

            item.DropDownItems.Add("&Save",null,filesave);

            item.DropDownItems.Add("&Exit", null, closeandexit);

            //items are added to menu

            menu1.Items.Add(item);

            //menu is added to form

            this.Controls.Add(menu1);

        }

        //event handlers for fileopen,filesave and exit 

 

        private void fileopen(object sender, EventArgs e)

        {

            openFileDialog1.Filter = "text files | *.txt";

            

            openFileDialog1.ShowDialog();

 

        }

    

        private void closeandexit(object sender,EventArgs e)

        {

            Application.Exit();

    }

 

        private void filesave(object sender ,EventArgs e)

        {

            saveFileDialog1.Filter = "text files | *.txt";

            saveFileDialog1.ShowDialog();

            MessageBox.Show("file saved...");

 

    }


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply

    Read also another Resources from the same Author

Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend