在C#的运行时创建上下文菜单 [英] Create a context menu at runtime in C#

查看:63
本文介绍了在C#的运行时创建上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人想在运行时使用C#在Windows窗体中使用DB中的数据创建上下文菜单.请协助我开始.

在此先感谢

Do anyone have an idea of creating a context menu at run time with the data from DB in windows forms using C#. Kindly assist me to start.

Thanks in Advance

推荐答案

创建上下文菜单很容易:
Creating the context menu is easy:
MenuItem[] mi = new MenuItem[3];
mi[0] = new MenuItem("Item1", MenuItem_Click);
mi[1] = new MenuItem("Item2", MenuItem_Click);
mi[2] = new MenuItem("Item3", MenuItem_Click);
ContextMenu cm = new ContextMenu(mi);
myPanel.ContextMenu = cm;


处理程序也很简单:


And the handler is simple too:

void MenuItem_Click(object sender, EventArgs e)
    {
    MenuItem mi = sender as MenuItem;
    if (mi != null)
        {
        MessageBox.Show(mi.Text);
        }
    }

您要做的就是从数据库中检索适当的数据,并根据需要进行替换.
如果您不了解更多详细信息,我们将无法为您提供更多帮助! :laugh:

All you have to do is retrieve the appropriate data from your DB and replace as necessary.
We can''t help you much more without knowing a lot more details! :laugh:


您的意思是操作系统范围的上下文菜单:

向Windows资源管理器添加上下文菜单 [ http://msdn.microsoft.com/en-us/library/aa984254%28v = vs.71%29.aspx [ ^ ]

或控件范围内的上下文菜单:
http://www.dotnetperls.com/contextmenustrip [
Did you mean an operating system wide context menu :

Add a context menu to the Windows Explorer[^]

Or a window wide context menu :
http://msdn.microsoft.com/en-us/library/aa984254%28v=vs.71%29.aspx[^]

Or a control wide context menu :
http://www.dotnetperls.com/contextmenustrip[^]

Hope it helps.


这篇关于在C#的运行时创建上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆