是否可以向CheckMenuStrip添加像CheckBox这样的控件?
我希望能够在选择菜单选项之前勾选几个选项。
这就是我现在所做的,但我已经注释了我尝试添加chkBox的位置 - 因为它不起作用:
DataGridView gridView = sender as DataGridView;
ContextMenuStrip my_menu = new ContextMenuStrip();
int colIndex = gridView.HitTest(e.X, e.Y).ColumnIndex;
Globals.PlotColumnIndex = colIndex;
my_menu.Items.Add("New plot").Name = "New plot";
my_menu.Items.Add("New trades plot").Name = "New trades plot";
my_menu.Items.Add("Add to existing plot").Name = "Add to existing plot";
my_menu.Items.Add("Add to existing plot Y2").Name = "Add to existing plot Y2";
CheckBox chkBox = new CheckBox();
chkBox.Text = "Option 1";
//my_menu.Controls.Add(chkBox);
my_menu.Show(gridView, new Point(e.X, e.Y));
my_menu.ItemClicked += new ToolStripItemClickedEventHandler(my_menu_ItemClicked);
答案 0 :(得分:0)
使用ToolStripControlHost
是一个选项:
var cb = new CheckBox();
cb.Text = "Checkbox 1";
var tch = new ToolStripControlHost(cb);
menu.Items.Add(tch);