简体   繁体   中英

ToolStrip Controls MouseClick?

I want to check if the user did right click on a button which is in a toolStrip, but there's no MouseClick event for each control.

example of right clicking:

    private void tabControl1_MouseClick(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Right)
        {
            Point pt = tabControl1.PointToScreen(e.Location);
            tabContxt.Show(pt);
        }
    }

i want to do the same for the button in the toolStrip, if you can help me :). Thanks

You can use Mouse_Down event.

private void toolStripButton1_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
    }
}

Try this

private void tabControl1_MouseClick(object sender, MouseEventArgs e)
{
    var zz = ((MouseEventArgs)e).Button;

    if (zz == MouseButtons.Right)
    {
        Point pt = tabControl1.PointToScreen(e.Location);
        tabContxt.Show(pt);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM