如何在ListBox项中添加菜单 [英] How To Add menu in ListBox Items
本文介绍了如何在ListBox项中添加菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的win表单中为每个listBox项添加一些菜单。
我在Google上发现了许多文章,用于在listBox中启用ContextMenuStrip,但这不是正在运行。
i希望菜单在我将鼠标光标移动到listBox项目后立即显示。
请帮助。
I want to add some menu to each listBox items in my win form.
I have found many articles on Google for enabling ContextMenuStrip in listBox but that is not working up.
i want the menu to appear as soon i move my mouse cursor on listBox item.
please help.
推荐答案
以下是您可以通过它的示例
Here is the example you can go through it
public partial class Form1 : Form
{
RadListBox listBox = new RadListBox();
public Form1()
{
InitializeComponent();
this.Controls.Add(listBox);
listBox.DataSource = new string[] { "1", "2", "3" };
RadContextMenu menu = new RadContextMenu();
RadContextMenuManager mgr = new RadContextMenuManager();
mgr.SetRadContextMenu(listBox, menu);
menu.DropDownOpening += new System.ComponentModel.CancelEventHandler(menu_DropDownOpening);
}
void menu_DropDownOpening(object sender, System.ComponentModel.CancelEventArgs e)
{
RadContextMenu menu = (RadContextMenu)sender;
menu.Items.Clear();
RadElement elementAtPoint = this.listBox.ElementTree.GetElementAtPoint(this.listBox.ListBoxElement.PointFromScreen(Control.MousePosition));
if (elementAtPoint is RadListBoxItem)
{
// Add menu options based on the item.
menu.Items.Add(new RadMenuItem((elementAtPoint as RadListBoxItem).Text));
}
}
}
这篇关于如何在ListBox项中添加菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文