方法:
1、創建一個菜單項數組。
2、在數組中增加菜單項
3、創建一個彈出式引用菜單
4、將菜單與菜單項加入到彈出式引用菜單中
5、將控件的ContextMenuStrip屬性設置成彈出菜單
如下例:
例1:
例2:
//
1、
ToolStripMenuItem:表示顯示在 MenuStrip 或 ContextMenuStrip 上的可選取選項。
ToolStripItem[] tsmRtbMenuu =
new ToolStripItem[
6];
//
2、
增加菜單項目集內容及對應方法
tsmRtbMenuu[
0] =
new ToolStripMenuItem(
"
保存GUID
",
null,
new EventHandler(btnWrite_Click));
tsmRtbMenuu[
1] =
new ToolStripMenuItem(
"
另存GUID
",
null,
new EventHandler(aonterSaveToolStripMenuItem_Click));
//
增加菜單項目分隔線
tsmRtbMenuu[
2] =
new ToolStripSeparator();
tsmRtbMenuu[
3] =
new ToolStripMenuItem(
"
複製
",
null,
new EventHandler(rtbCopy_changed));
tsmRtbMenuu[
4] =
new ToolStripSeparator();
tsmRtbMenuu[
5] =
new ToolStripMenuItem(
"
打印
",
null,
new EventHandler(printToolStripMenuItem_Click));
//3、 定義快速功能表
ContextMenuStrip ctmsRtbMenu =
new ContextMenuStrip();
//4、 將菜單加入到功能表中
ctmsRtbMenu.Items.AddRange(tsmRtbMenuu);
//5、 調用快速功能表(將功能表加入到控件右鍵菜單中)
//
rtbGuidValue為RichTextBox控件
rtbGuidValue.ContextMenuStrip = ctmsRtbMenu;
1、創建一個菜單項數組。
2、在數組中增加菜單項
3、創建一個彈出式引用菜單
4、將菜單與菜單項加入到彈出式引用菜單中
5、將控件的ContextMenuStrip屬性設置成彈出菜單
如下例:
例1:
//
ToolStripMenuItem:表示顯示在 MenuStrip 或 ContextMenuStrip 上的可選取選項。
//1、 定義菜單項目集
ToolStripMenuItem[] formMenuItemList = new ToolStripMenuItem[2];
// 2、增加菜單項目集內容及對應方法
formMenuItemList[0] = new ToolStripMenuItem("Save Member", null, new EventHandler(saveMemberClick));
formMenuItemList[1] = new ToolStripMenuItem("Clear", null, new EventHandler(clearClick));
// ContextMenuStrip:表示快速鍵功能表。
//3、 定義快速功能表
ContextMenuStrip formMenu = new ContextMenuStrip();
//4、 將菜單加入到功能表中
formMenu.Items.AddRange(formMenuItemList);
//5、 調用快速功能表
this.ContextMenuStrip = formMenu;
//1、 定義菜單項目集
ToolStripMenuItem[] formMenuItemList = new ToolStripMenuItem[2];
// 2、增加菜單項目集內容及對應方法
formMenuItemList[0] = new ToolStripMenuItem("Save Member", null, new EventHandler(saveMemberClick));
formMenuItemList[1] = new ToolStripMenuItem("Clear", null, new EventHandler(clearClick));
// ContextMenuStrip:表示快速鍵功能表。
//3、 定義快速功能表
ContextMenuStrip formMenu = new ContextMenuStrip();
//4、 將菜單加入到功能表中
formMenu.Items.AddRange(formMenuItemList);
//5、 調用快速功能表
this.ContextMenuStrip = formMenu;
例2:











//3、 定義快速功能表

//4、 將菜單加入到功能表中

//5、 調用快速功能表(將功能表加入到控件右鍵菜單中)


转自:http://www.cnblogs.com/scottckt/archive/2007/11/21/967719.html