为什么我不能使ToolStripMenuItem == True?如何检查菜单项是否被点击?

时间:2018-02-20 00:16:25

标签: c# winforms toolstrip

public partial class Form1 : Form
{
    public double[] pricearray = new double[] { 20.00, 50.00, 45.00, 40.00, 
    25.00, 80.00 };
    public double shipping = 0;
    public int quant = 0;
    public double bagquant = 0;
    public double bagprice = 0;
    public double shiptotal = 0;
    public double total = 0;
    private object eventhandler;

    public Form1()

上面我宣布公共变量

    private void fileToolStripMenuItem_Click(object sender, EventArgs e)
    {
        if (clearToolStripMenuItem.Click == true)

        { 
        double shipping = 0;
        int quant = 0;
        double bagquant = 0;
        double bagprice = 0;
        double shiptotal = 0;
        double total = 0;
        }

        if (exitToolStripMenuItem.Click = true) 
        {
            Application.Exit();
        }
    }

这是在线商店的表格。这是为了清除用户可能做出的任何选择。

1 个答案:

答案 0 :(得分:0)

您可以将发件人转换为工具条菜单项,然后检查其名称。

private void fileToolStripMenuItem_Click(object sender, EventArgs e)
{
    if (((ToolStripMenuItem)sender).Name == clearToolStripMenuItem.Name )
    { 
        double shipping = 0;
        int quant = 0;
        double bagquant = 0;
        double bagprice = 0;
        double shiptotal = 0;
        double total = 0;
        // I ASSUME YOU ARE DOING MORE THAN DECLARING LOCAL VARIABLES
    }
    else if (((ToolStripMenuItem)sender).Name == exitToolStripMenuItem.Name )
    {
        Application.Exit();
    }
}