[原创]c# listbox 右键菜单 判断选择和不选中分别弹出不同的内容

    {

            if (e.Button == MouseButtons.Right)
            {

                ListBox listBox = (ListBox)sender;
                //listBox.SelectedItem
                //object obj=listBox.GetChildAtPoint(e.Location);
                int x = e.X;
                int y = e.Y;
                int currentIndex = e.Y / listBox.ItemHeight;
                bool onlyShowCopy = false;
                if (listBox.Items.Count == 0 || currentIndex >= listBox.Items.Count)
                {
                    //MessageUtil.showMessgae("不应该弹出菜单");
                    //MessageUtil.showMessgae("请选择一个键盘页");
                    //contextMenu
                    onlyShowCopy = true;
                }
                else

                {

                }

                contextMenuStripKeyboardPage.Items[0].Visible = !onlyShowCopy;
                contextMenuStripKeyboardPage.Items[1].Visible = !onlyShowCopy;
                contextMenuStripKeyboardPage.Items[2].Visible = !onlyShowCopy;
                contextMenuStripKeyboardPage.Items[3].Visible =onlyShowCopy;
                //contextMenuStripKeyboardPage.Items[3].Visible = !onlyShowCopy;

            }

你可能感兴趣的:([原创]c# listbox 右键菜单 判断选择和不选中分别弹出不同的内容)