When button clicked
i want when i create the button and click a menu appear in my windows application !! using c#
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Gopal Mahadak136 reputationPosted Jun 29, 2012, 7:25 PM EDT
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 WindowsFormsApplication10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Button myText = new Button();
myText.Location = new Point(25, 35);
myText.Text = "First";
myText.Click += new EventHandler(myText_Click);
this.Controls.Add(myText);
}
private void myText_Click(object sender, EventArgs e)
{
MainMenu mnuFileMenu = new MainMenu();
this.Menu = mnuFileMenu;
MenuItem myMenuItemFile = new MenuItem("&File");
MenuItem m3 = new MenuItem("new");
MenuItem m4 = new MenuItem("open");
mnuFileMenu.MenuItems.Add(myMenuItemFile);
myMenuItemFile.MenuItems.Add(m3);
myMenuItemFile.MenuItems.Add(m4);
}
}
}
Hemant KumarRank #1,202 · 1.5K reputationPosted Jun 29, 2012, 3:01 AM EDT
private voi btn_click(object sender,EventArgs e)
{
menu1.Visible=true;
}
younis abdeljawwad67 reputationPosted Jun 29, 2012, 3:46 AM EDT
Gopal Mahadak136 reputationPosted Jun 29, 2012, 4:48 AM EDT
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 WindowsFormsApplication10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Button myText = new Button();
myText.Location = new Point(25, 35);
myText.Text = "First";
myText.Click += new EventHandler(myText_Click);
this.Controls.Add(myText);
}
private void myText_Click(object sender, EventArgs e)
{
MainMenu mnuFileMenu = new MainMenu();
this.Menu = mnuFileMenu;
MenuItem myMenuItemFile = new MenuItem("&File");
mnuFileMenu.MenuItems.Add(myMenuItemFile);
}
}
}
younis abdeljawwad67 reputationPosted Jun 29, 2012, 7:31 AM EDT