c#.net-Add context menu at runtime.


 

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

 

namespace MyContextMenu

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)

        {

           

            ContextMenuStrip myContextMenu = new ContextMenuStrip();

            this.ContextMenuStrip = myContextMenu;

 

            ToolStripMenuItem myFirstTooltip = new ToolStripMenuItem();

            ToolStripMenuItem mySecondTooltip = new ToolStripMenuItem();

            ToolStripMenuItem myThirdTooltip = new ToolStripMenuItem();

 

            myFirstTooltip.Text = "Item One";

            mySecondTooltip.Text = "Item Two";

            myThirdTooltip.Text = "Item Three";

 

            myContextMenu.Items.Add(myFirstTooltip);

            myContextMenu.Items.Add(mySecondTooltip);

            myContextMenu.Items.Add(myThirdTooltip);

        }

    }

}


Ebook Download
View all
Learn
View all