create a C# context menu from code

I try the one of your approach,
it works well in my computer. Below is my code:

 public void AddContextMenu()
{
ContextMenu mnuContextMenu = new ContextMenu();
mnuContextMenu.MenuItems.Add("&Red LED", new EventHandler(SetDisplayRed));
mnuContextMenu.MenuItems.Add("&Blue LED", new EventHandler(SetDisplayBlue));
mnuContextMenu.MenuItems.Add("&LCD", new EventHandler(SetDisplayLCD));
textBox1.ContextMenu = mnuContextMenu;
this.ContextMenu = mnuContextMenu;
}

private void SetDisplayRed(object sender, EventArgs e)
{

textBox1.BackColor = Color.Maroon;
textBox1.ForeColor = Color.OrangeRed;
}

private void SetDisplayBlue(object sender, EventArgs e)
{
textBox1.BackColor = Color.Red;
textBox1.ForeColor = Color.Gray;
}

private void SetDisplayLCD(object sender, EventArgs e)
{
textBox1.BackColor = Color.Beige;
textBox1.ForeColor = Color.Blue;
}


>When I right-click on the textbox I get a menu with
Undo/Cut/Copy/Paste/Select All.  And when I right-click on the form I get
nothing

Have you already added your "AddContextMenu()" method into the
contruction method of your mainform?

public MainForm()
{
InitializeComponent();

AddContextMenu();
}

create a C# context menu from code

时间: 2025-01-07 15:18:02

create a C# context menu from code的相关文章

create Context Menu in Windows Forms application using C# z

In this article let us see how to create Context Menu in Windows Forms application using C# Introduction In this article we will see how to create Context Menu or Popup Menu or Shortcut menu in Windows Forms application with ContextMenuStrip control

Create Primary Key using Entity Framework Code First

原文:http://www.codeproject.com/Articles/813912/Create-Primary-Key-using-Entity-Framework-Code-Fir Introduction This article describes the effect of Entity Framework Code First convention and configuration for creating Primary Key column. Entity Framew

sublime text 3-right click context menu

dd a system wide windows explorer button " Edit with Sublime" similar to how Notepad++ does it or some other editors?See attached screenshot. (I know this is an old thread, but since I dropped by looking for the same information and found it els

Windows context menu shortcut key

Besides the context menu key, you have another option to trigger the context menu: Shift+F10. This is especially useful when your computer/laptop (Lenovo W530) hasn't a context menu key. Reference: Lenovo W530 and the Context Menu Key

Android -- Options Menu,Context Menu,Popup Menu

Options Menu                                                                           创建选项菜单的步骤: 1.覆盖Activity 的onCreateOptionMenu(Menu menu)方法,当菜单第一次被打开时调用 2.调用Menu 的add( )方法添加菜单项(MenuItem),同时可以调用MenuItem 的setIcon( )方法来为菜单项设置图标 3.当菜单项(MenuItem)被选择时,

Show Notepad++ in Windows Explorer context menu

Keywords: Register, Explorer context menu, Edit with Notepad++ Need to show "Edit with Notepad++" in Windows Explorer? If you have a copy (not installed) of Notepad++ and want this command in Explorer, register the following dll. regsvr32  D:\No

Tree Context Menu

Right click on a node to display context menu. My Documents Photos Program Files Intel Java Microsoft Office Games index.html about.html welcome.html 源代码 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>T

removing right click context menu options on recycle bin

Humpty is correct as always  First you might want to make a backup of the reg key then remove the Washer entries using a reg fix to save you having to manually edit the registry. Goto Start Menu > Run > Type (or copy and paste) this into the run box

Creating Context Menu / 创建上下文菜单项 / Win32, VC++, Windows, DLL, ATL, COM

创建上下文菜单项 1.新建一个ATL Project. 2.建议将Project Property中Linker – General - “Register Output” 设为no,C/C++ - “Code Generation” - “Runtime Library” 设为 /MTd. 3.在Solution Explorer中右键Add Class,选择ATL Simple Object.并在弹出的对话框中为该Class命名. 4.添加完成后建议Build一下Project,MIDL c