简体   繁体   中英

Check to see if toolstripmenuitem is checked

    private void Form1_FormClosed(object sender, FormClosedEventArgs e)
    {
        if (clearHistoryOnQuitToolStripMenuItem.Checked)
        {
            System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 255");
        }

    }

I don't get any errors but the program still performs the action inside the if statement even if the Item is unchecked.

There is no problem with what you have done implementing the if statement, so there must be an issue with something external to what you have provided above.

Just be sure of the Checked state prior to entering the if statement before you go any further... You may find your answer right then and there.

Try the following and see what writes to the console when run.

private void Form1_FormClosed(object sender, FormClosedEventArgs e)
    {
        Console.WriteLine(clearHistoryOnQuitToolStripMenuItem.CheckState.ToString());
        if (clearHistoryOnQuitToolStripMenuItem.Checked)
        {
            System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 255");
        }

    }

Best of luck & at least from here you will be able to figure out why your Checked state is always returning true (or is it!)...

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