简体   繁体   English

上下文菜单项

[英]Context menu items

I made context menu for UltrawinGrid, when i click right mouse button then the context menu open. 我为UltrawinGrid创建了上下文菜单,当我单击鼠标右键然后打开上下文菜单时。

This is the code that I use for my menu: 这是我用于菜单的代码:

Private Sub ShowContextMenu(ByVal mousePoint As Point)
        Dim cMenu As ContextMenu = New ContextMenu


        cMenu.MenuItems.Add("Delete")
        cMenu.MenuItems.Add("Copy")
        cMenu.MenuItems.Add("Paste")

        cMenu.Show(UltraGrid1, mousePoint)

    End Sub

Now I want when I click on context menu item, for example delete, to call function that gone do something, how i can do this? 现在,当我单击上下文菜单项(例如删除)时,我想调用已执行某项操作的函数,我该怎么做? How I can make connection between menu items and functions? 如何在菜单项和功能之间建立联系?

You have to add an event handler: 您必须添加一个事件处理程序:

cMenu.MenuItems.Add("Delete", mnuDelete_OnClick)

And the method: 和方法:

Private Sub mnuDelete_OnClick(sender As System.Object, e As System.EventArgs)
End Sub

Not sure about the UltrawinGrid, but typically you should be able to associate a Context Menu to a control. 不确定UltrawinGrid,但是通常您应该能够将上下文菜单关联到控件。 Context Menu control is available in your toolbox as ContextMenuStrip. 上下文菜单控件在您的工具箱中作为ContextMenuStrip提供。 Drop that in your designer, specify the menu item and wire up the event through the designer. 将其放置在设计器中,指定菜单项,然后通过设计器连接事件。 That is much easier way to do it. 那是容易得多的方法。

For whatever reason if you cant do the above, you will have to manually for each menu item wireup your own event handler in the code like this: 无论出于什么原因,如果您不能执行上述操作,则必须手动为每个菜单项在代码中连接您自己的事件处理程序,如下所示:

    cMenuSubItem1.Click +=new EventHandler(tesToolStripMenuItem_Click);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM