开发者

contextmenustrip: check selected item

I have a contextmenustrip tha开发者_如何学JAVAt contains some option, I have almost implemented everything, i just want to check which items i have selected in options_MouseClick

  private void ConsoleRichTextBox_MouseDown(object sender, MouseEventArgs e)
    {

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

            options.Show();
            Point currentPoint;
            currentPoint = new Point(e.X, e.Y);
            options.Show(ConsoleRichTextBox, currentPoint);
        }

    }

    private void options_MouseClick(object sender, MouseEventArgs e)
    {
         //if options selected = clear
        ConsoleRichTextBox.Clear();
    }


You should just handle the Click event of each of the menu items. There's no need to handle the MouseClick event of a contextmenustrip. Also you can add multiple handlers to the same method and differentiate with the sender parameter as this will refer to the exact menu item that was clicked.

        ToolStripMenuItem tsmi = new ToolStripMenuItem();
        tsmi.Click += tsmi_Click;

and:

    public void tsmi_Click(object sender, EventArgs  e)
    {
        if (sender == tsmi)
        {
            // Do stuff
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜