Adding Menus in Windows Application Like Notepad

Manimaddu
Posted by Manimaddu under ASP.NET category on | Points: 40 | Views : 422
Hi All...

The following code is to display menus like notepad menu in windows application

Form.cs:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AddingMenus
{
public partial class frmMyForm : Form
{
TextBox txtBox1;
TextBox txtBox2;
public frmMyForm()
{
InitializeComponent();
MyMenuBar();
Operation();
}
public void Operation()
{
txtBox1 = new TextBox();
txtBox2 = new TextBox();
txtBox1.Location = new Point(15,15);
txtBox2.Location = new Point(15 + txtBox1.Location.X+txtBox1.Size.Width, 15);
txtBox1.Size = new Size(90, 20);
txtBox2.Size = new Size(90, 20);
this.Controls.Add(txtBox1);
this.Controls.Add(txtBox2);
}
public void MyMenuBar()
{
MainMenu mnuFileMenu = new MainMenu();
this.Menu = mnuFileMenu;
MenuItem myMenuItemFile = new MenuItem("&File");
MenuItem myMenuItemNew = new MenuItem("&New");
MenuItem myMenuItemOpen = new MenuItem("&Open");
MenuItem myMenuItemsave = new MenuItem("&Save");
MenuItem myMenuItemsaveAs = new MenuItem("&Save &As");
MenuItem myMenuItemPageSetup = new MenuItem("&Page &Setup");
MenuItem myMenuItemPrint = new MenuItem("&Print");
MenuItem myMenuItemExit = new MenuItem("&Exit",new EventHandler(myMenuItemExit_Click));
mnuFileMenu.MenuItems.Add(myMenuItemFile);
myMenuItemFile.MenuItems.Add(myMenuItemNew);
myMenuItemFile.MenuItems.Add(myMenuItemOpen);
myMenuItemFile.MenuItems.Add(myMenuItemsave);
myMenuItemFile.MenuItems.Add(myMenuItemsaveAs);
myMenuItemFile.MenuItems.Add(myMenuItemPageSetup);
myMenuItemFile.MenuItems.Add(myMenuItemPrint);
myMenuItemFile.MenuItems.Add(myMenuItemExit);

MenuItem myMenuItemEdit = new MenuItem("&Edit");
MenuItem myMenuItemUndo = new MenuItem("&Undo");
MenuItem myMenuItemCut = new MenuItem("&Cut",new EventHandler(myMenuItemCut_Click));
MenuItem myMenuItemCopy = new MenuItem("&Copy",new EventHandler(myMenuItemCopy_Click));
MenuItem myMenuItemPaste = new MenuItem("&Paste",new EventHandler(myMenuItemPaste_Click));
MenuItem myMenuItemDelete = new MenuItem("&Delete");
MenuItem myMenuItemFind = new MenuItem("&Find");
MenuItem myMenuItemFindNext = new MenuItem("&Find &Next");
MenuItem myMenuItemRepalce = new MenuItem("&Replace");
MenuItem myMenuItamGoTo = new MenuItem("GoTo");
mnuFileMenu.MenuItems.Add(myMenuItemEdit);
myMenuItemEdit.MenuItems.Add(myMenuItemUndo);
myMenuItemEdit.MenuItems.Add(myMenuItemCut);
myMenuItemEdit.MenuItems.Add(myMenuItemCopy);
myMenuItemEdit.MenuItems.Add(myMenuItemPaste);
myMenuItemEdit.MenuItems.Add(myMenuItemDelete);
myMenuItemEdit.MenuItems.Add(myMenuItemFind);
myMenuItemEdit.MenuItems.Add(myMenuItemFindNext);
myMenuItemEdit.MenuItems.Add(myMenuItemRepalce);
myMenuItemEdit.MenuItems.Add(myMenuItamGoTo);

MenuItem myMenuItemFormat = new MenuItem("&Format");
MenuItem myMenuItemWordWrap = new MenuItem("&Word &Wrap");
MenuItem myMenuItemFont = new MenuItem("Font");
mnuFileMenu.MenuItems.Add(myMenuItemFormat);
myMenuItemFormat.MenuItems.Add(myMenuItemWordWrap);
myMenuItemFormat.MenuItems.Add(myMenuItemFont);
}
private void myMenuItemExit_Click(object sender, EventArgs e)
{
Application.Exit();
}

private void Form1_Load(object sender, EventArgs e)
{

}
private void myMenuItemCopy_Click(object sender, EventArgs e)
{
txtBox1.Copy();
}
private void myMenuItemPaste_Click(object sender, EventArgs e)
{
txtBox2.Paste();

}
private void myMenuItemCut_Click(object sender, EventArgs e)
{
txtBox1.Cut();
}
}
}



Thank You..

Comments or Responses

Login to post response