本文介绍了在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
推荐答案
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:
这篇关于在C#的运行时创建上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!