Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ToolStripMenuItem.Visible always returns false?

ToolStripMenuItem.Visible always returns false?

Scheduled Pinned Locked Moved C#
question
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AussieLew
    wrote on last edited by
    #1

    I have just struck this. Using VS2008

    private void button2_Click(object sender, EventArgs e)
    {

        // ToolStripMenuItem.Visible always returns false?
            // This has the effect of not being able to toggle or invert the state to false by
            // assigning its negated value by use of the ! operator.
            // If the initial state is Visible = false the first click will toggle to Visible = true
            // Subsequent clicks do not change the Visible property as Visible always returns false
            // So, no matter the true state it will always set Visible = true rather than the inverse;
            
    
            // always returns false even if set to Visible
            bool cond1 = this.confirmDeletesToolStripMenuItem.Visible; 
    
            // always returns true
            bool cond2 = !this.confirmDeletesToolStripMenuItem.Visible; 
    
            MessageBox.Show(string.Format("Cond1 = {0} Cond2 = {1}",cond1,cond2));
    
            // try to invert the value of confirmDeletesToolStripMenuItem.Visible 
            this.confirmDeletesToolStripMenuItem.Visible = !this.confirmDeletesToolStripMenuItem.Visible;
    
            // still always returns false
            cond1 = this.confirmDeletesToolStripMenuItem.Visible; 
    
            // still always returns true
            cond2 = !this.confirmDeletesToolStripMenuItem.Visible; 
    
            MessageBox.Show(string.Format("Cond1 = {0} Cond2 = {1}", cond1, cond2));
    
            
            }
    

    Thanks for any clues!

    J G 2 Replies Last reply
    0
    • A AussieLew

      I have just struck this. Using VS2008

      private void button2_Click(object sender, EventArgs e)
      {

          // ToolStripMenuItem.Visible always returns false?
              // This has the effect of not being able to toggle or invert the state to false by
              // assigning its negated value by use of the ! operator.
              // If the initial state is Visible = false the first click will toggle to Visible = true
              // Subsequent clicks do not change the Visible property as Visible always returns false
              // So, no matter the true state it will always set Visible = true rather than the inverse;
              
      
              // always returns false even if set to Visible
              bool cond1 = this.confirmDeletesToolStripMenuItem.Visible; 
      
              // always returns true
              bool cond2 = !this.confirmDeletesToolStripMenuItem.Visible; 
      
              MessageBox.Show(string.Format("Cond1 = {0} Cond2 = {1}",cond1,cond2));
      
              // try to invert the value of confirmDeletesToolStripMenuItem.Visible 
              this.confirmDeletesToolStripMenuItem.Visible = !this.confirmDeletesToolStripMenuItem.Visible;
      
              // still always returns false
              cond1 = this.confirmDeletesToolStripMenuItem.Visible; 
      
              // still always returns true
              cond2 = !this.confirmDeletesToolStripMenuItem.Visible; 
      
              MessageBox.Show(string.Format("Cond1 = {0} Cond2 = {1}", cond1, cond2));
      
              
              }
      

      Thanks for any clues!

      J Offline
      J Offline
      johannesnestler
      wrote on last edited by
      #2

      Hmm? There must be something wrong, but what? I checked your code on my system (using VS2008, .NET 3.5) it worked as expected. Can you set the Visible-property?

      confirmDeletesToolStripMenuItem.Visible = false;

      A 2 Replies Last reply
      0
      • A AussieLew

        I have just struck this. Using VS2008

        private void button2_Click(object sender, EventArgs e)
        {

            // ToolStripMenuItem.Visible always returns false?
                // This has the effect of not being able to toggle or invert the state to false by
                // assigning its negated value by use of the ! operator.
                // If the initial state is Visible = false the first click will toggle to Visible = true
                // Subsequent clicks do not change the Visible property as Visible always returns false
                // So, no matter the true state it will always set Visible = true rather than the inverse;
                
        
                // always returns false even if set to Visible
                bool cond1 = this.confirmDeletesToolStripMenuItem.Visible; 
        
                // always returns true
                bool cond2 = !this.confirmDeletesToolStripMenuItem.Visible; 
        
                MessageBox.Show(string.Format("Cond1 = {0} Cond2 = {1}",cond1,cond2));
        
                // try to invert the value of confirmDeletesToolStripMenuItem.Visible 
                this.confirmDeletesToolStripMenuItem.Visible = !this.confirmDeletesToolStripMenuItem.Visible;
        
                // still always returns false
                cond1 = this.confirmDeletesToolStripMenuItem.Visible; 
        
                // still always returns true
                cond2 = !this.confirmDeletesToolStripMenuItem.Visible; 
        
                MessageBox.Show(string.Format("Cond1 = {0} Cond2 = {1}", cond1, cond2));
        
                
                }
        

        Thanks for any clues!

        G Offline
        G Offline
        Gonzalo Cao
        wrote on last edited by
        #3

        I don't think this is the problem, but just in case: If you check the value on step by step debug the value will always be false, since the window is hidden by visual studio.

        1 Reply Last reply
        0
        • J johannesnestler

          Hmm? There must be something wrong, but what? I checked your code on my system (using VS2008, .NET 3.5) it worked as expected. Can you set the Visible-property?

          confirmDeletesToolStripMenuItem.Visible = false;

          A Offline
          A Offline
          AussieLew
          wrote on last edited by
          #4

          johannesnestler wrote:

          Can you set the Visible-property?

          Yes, I can set the Visible property to either True or False directly. And that works. It is only when trying to toggle it by using the ! operator it always returns True. (Because getting the value of .Visible always returns False) So if I set it either in the property grid or in code, to False. The MenuItem is Not visible as expected. The first toggle using the ! operator then makes it visible, further toggles continue to leave it visible as it just keeps setting it to True. (because this.confirmDeletesToolStripMenuItem.Visible continues to return false!) Without worry about my previous code, to simplify my example, even if I do something like....

          this.confirmDeletesToolStripMenuItem.Visible = true;
          mbox("Visible = " + this.confirmDeletesToolStripMenuItem.Visible.ToString());

          I still get False! ??

          1 Reply Last reply
          0
          • J johannesnestler

            Hmm? There must be something wrong, but what? I checked your code on my system (using VS2008, .NET 3.5) it worked as expected. Can you set the Visible-property?

            confirmDeletesToolStripMenuItem.Visible = false;

            A Offline
            A Offline
            AussieLew
            wrote on last edited by
            #5

            I had a thought after my last post. The confirmDeletesToolStripMenuItem is not the topmost menuitem. If I get the value of any top level menu item it returns the correct value i.e True if set to Visible = True; Whereas the lower menu levels return False even if set to True. I would have thought that the Visible property is a reflection of whether it should be displayed rather than whether it can be seen? Getting closer but stranger?

            modified on Saturday, August 28, 2010 3:17 AM

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups