Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Menu Opening Form

Status
Not open for further replies.

DESMAN2003

Programmer
Oct 27, 2003
24
AU
Hi, I have a problem with trying to figure out how to open another form when you click on a Menu Item in C# (Visual Studio .NET). Does anyone know how to do it? My main form is called Form1 and the one I want to be able to open is Form3. I want this to occur when the menu item called "Range" is clicked on.

My code so far is quite little:

private void Form1_Load(object sender, System.EventArgs e)
{
if (System.Windows.Forms.MenuItem.Click = "Range")

}

Thanks in advance :)
 
Try with the code as bellow:

private void Form1_Load(object sender, System.EventArgs e)
{
CreateMyMenu();
}

public void CreateMyMenu()
{
// Create a main menu object.
MainMenu mainMenu1 = new MainMenu();

// Create empty menu item objects.
MenuItem topMenuItem = new MenuItem();
MenuItem menuItem1 = new MenuItem();

// Set the caption of the menu items.
topMenuItem.Text = "&File";
menuItem1.Text = "&Open";

// Add the menu items to the main menu.
topMenuItem.MenuItems.Add(menuItem1);
mainMenu1.MenuItems.Add(topMenuItem);

// Add functionality to the menu items using the Click event.
menuItem1.Click += new System.EventHandler(this.menuItem1_Click);

// Assign mainMenu1 to the form.
this.Menu=mainMenu1;
}

private void menuItem1_Click(object sender, System.EventArgs e)
{
Form3 fr=new Form3();
fr.Show();
}


Uyen Chi
Software developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top