我正在寻找一种方法来为程序提供导致 ContextMenuStrip 打开的控件。我正在为多个组合框分配相同的条以重复使用它们,就像在课程开始时一样。
myComboBox.ContextMenuStrip = changevaluestrip;
这里我有“添加值”和“删除值”,当然它们中的每一个都必须知道它必须从哪个组合框中删除值。我试着用
private void removeValueToolStrip_Click(object sender, EventArgs e)
{
ToolStripMenuItem usedbox = sender as ToolStripMenuItem;
var parent = usedbox.GetCurrentParent();
DialogResult res = MessageBox.Show("Do you really want to delete this value?", "Delete Value", MessageBoxButtons.YesNo);
if (res == DialogResult.Yes)
{
//Delete it from the combobox it was sent from
}
}
但这并没有真正奏效,只是给了我“删除价值”作为发件人......