Buttons visibility

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Djiber
    New Member
    • Apr 2012
    • 15

    Buttons visibility

    I have app in which I would like to use buttons as an Drop Down menu.

    Code:
    private void button16_Click(object sender, EventArgs e)
            {
                    button1.Visible = true;
                    button2.Visible = true;
                    button3.Visible = true;
                    button4.Visible = true;
                    button5.Visible = true;
                    button6.Visible = true;
                    button7.Visible = true;
                    button8.Visible = true;
                    button9.Visible = true;
                    button10.Visible = true;
                    button11.Visible = true;
                    button12.Visible = true;
                    button13.Visible = true;
                    button14.Visible = true;
                    button15.Visible = true;
            }
    
            private void button17_Click(object sender, EventArgs e)
            {
                button1.Visible = false;
                button2.Visible = false;
                button3.Visible = false;
                button4.Visible = false;
                button5.Visible = false;
                button6.Visible = false;
                button7.Visible = false;
                button8.Visible = false;
                button9.Visible = false;
                button10.Visible = false;
                button11.Visible = false;
                button12.Visible = false;
                button13.Visible = false;
                button14.Visible = false;
                button15.Visible = false;
            }
    All is working but turning buttons invisible again is really slow, turning them visible is completed in milliseconds while turning them invisible takes about 2-3 seconds.

    How can I speed that up?
  • RhysW
    New Member
    • Mar 2012
    • 70

    #2
    put it in a groupbox and instead of hiding and showing the buttons individually, hide the groupbox, will only require one process and therefore should be quicker, in theory

    edit: though on second thoughts its the drawing it to the UI thats eating up the time, which would still be a problem with hiding and showing the groupbox

    Comment

    • Djiber
      New Member
      • Apr 2012
      • 15

      #3
      Puting them in groupBox helped but now it's not pretty :P

      I still don't understand if drawing is the problem how is it easier to draw them(make them visible) then destroy them (make them invisible)

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Do you have event handlers attached to the visible state changes on any of the buttons?

        Comment

        • roshan ban
          New Member
          • Apr 2012
          • 21

          #5
          try the code as
          this.button1.Vi sible = false;
          for every button

          Comment

          • Djiber
            New Member
            • Apr 2012
            • 15

            #6
            @Plater
            How do you mean?

            I have EventHandlers for button.Click for what would I need it for Visible state? (Like I've said it's a Menu so I just need that Buttons are shown when I click on button that's always visible and that they disappear when I click on another+it makes visible another set of buttons)

            Comment

            • RhysW
              New Member
              • Mar 2012
              • 70

              #7
              If you click on the form and click one of the buttons then look in its properties window, click the lightning bolt (that takes you to that controls events) one of them will be VisibleChanged, this is code that is fired when the buttons visibility is changed from true to false or vice versa, i'm not sure how this event would help as the same code would need to be executed anyway and you would still have the same problem of it being slow to show them, but thats an explanation of the event anyhow

              Comment

              • RhysW
                New Member
                • Mar 2012
                • 70

                #8
                On a massive side note i just tried to replicate the problem you have, i used 26 buttons instead of your 15, hoping that this would exaggerate your problem, and i didnt have it, it showed just as quickly as it hid. So its nothing with your code, its literally just the speed that your computer is capable of hiding and drawing at (mine is only a month or so old so has next to nothing slowing it down) so yeah the problem is not the code, so you dont need to use the groupbox if you dont want to as there really isnt a way of speeding it up short of formatting your computer!

                Comment

                • Djiber
                  New Member
                  • Apr 2012
                  • 15

                  #9
                  Thank you for confirmation, computer I'm working on is old, has 1GB of RAM and 2,4 GHz CPU :P

                  Comment

                  • RhysW
                    New Member
                    • Mar 2012
                    • 70

                    #10
                    hehe thought it might be that the moment i tried it because i suddenly remembered doing something similar a few projects ago

                    Comment

                    Working...