Wed Apr 06, 2011 10:23 am
Wed Apr 06, 2011 10:39 pm
using System;
using System.Windows.Forms;
public class testForm : Form {
MainMenu menubarObj;
public testForm() {
Text = "Adding a Main Menu";
// Create a main menu object.
menubarObj = new MainMenu();
// Add top-level menu items to the menu.
MenuItem fileMenuIteam = new MenuItem("File");
menubarObj.MenuItems.Add(fileMenuIteam);
MenuItem toolMenuIteam = new MenuItem("Tools");
menubarObj.MenuItems.Add(toolMenuIteam);
// Create File submenu
MenuItem subfileMenuIteam = new MenuItem("Open File");
fileMenuIteam.MenuItems.Add(subfileMenuIteam);
MenuItem subtoolMenuIteam = new MenuItem("Close");
fileMenuIteam.MenuItems.Add(subtoolMenuIteam);
MenuItem exitIteam = new MenuItem("Exit");
fileMenuIteam.MenuItems.Add(exitIteam);
MenuItem changeIteam = new MenuItem("Change size");
toolMenuIteam.MenuItems.Add(changeIteam);
MenuItem restoreIteam = new MenuItem("Restore size");
toolMenuIteam.MenuItems.Add(restoreIteam);
// events call back function
subfileMenuIteam.Click += new EventHandler(openClick);
subtoolMenuIteam.Click += new EventHandler(closeClick);
exitIteam.Click += new EventHandler(exitClick);
changeIteam.Click += new EventHandler(changeClick);
restoreIteam.Click += new EventHandler(restoreClick);
// set the menu of the form
Menu = menubarObj;
}
[STAThread]
public static void Main() {
testForm formObj = new testForm();
Application.Run(formObj);
}
// Change action
protected void changeClick(object who, EventArgs e) {
// change size of window
Width = Height = 300;
}
// restore action
protected void restoreClick(object who, EventArgs e) {
// restore size of window
Width = Height = 400;
}
// open selection handling
protected void openClick(object who, EventArgs e) {
MessageBox.Show("not implemented", "not implemented",
MessageBoxButtons.OK);
}
// close click handling
protected void closeClick(object who, EventArgs e) {
MessageBox.Show("not implemented", "not implemented",
MessageBoxButtons.OK);
}
// exit with confirmation .
protected void exitClick(object who, EventArgs e) {
DialogResult answer = MessageBox.Show("Are you sure you want to exit",
"Exit",
MessageBoxButtons.YesNo);
if(answer == DialogResult.Yes) Application.Exit();
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.