mardi 3 juin 2014

How to check/uncheck menu item and keep windows on top


Vote count:

0




I am writing a C# web application where I have a menu strip with an option to keep windows always on top. The name of it is alwaysOnTopToolStripMenuItem and during page load I keep it checked because I start with the form being on top:



private void frmMain_Load(object sender, EventArgs e)
{
alwaysOnTopToolStripMenuItem.Checked = true;
}


I then have the following code to allow the user to select and change it based on the condition of the menu item:



private void alwaysOnTopToolStripMenuItem_Click(object sender, EventArgs e)
{
if (alwaysOnTopToolStripMenuItem.Checked == true)
{
MessageBox.Show("TRUE - SETTING TO FALSE");
alwaysOnTopToolStripMenuItem.Checked = false;
this.TopMost = false;
}
if (alwaysOnTopToolStripMenuItem.Checked == false)
{
MessageBox.Show("FALSE - SETTING TO TRUE");
alwaysOnTopToolStripMenuItem.Checked = true;
this.TopMost = true;
}
}


When it's commented out, If I go through the menu option, clicking it doesn't uncheck it and then clicking it again doesn't check it. It always remains checked.


The MessageBox displays both prompt no matter what I choose.


How can I fix the following:



  • Change check to uncheck and uncheck to check based on the current state?

  • Also, make the form TopMost based on the selection?



asked 1 min ago

SiKni8

1,585





Aucun commentaire:

Enregistrer un commentaire