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. Hiding/Showing panels

Hiding/Showing panels

Scheduled Pinned Locked Moved C#
question
10 Posts 5 Posters 1 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.
  • M Offline
    M Offline
    Megidolaon
    wrote on last edited by
    #1

    I try to hide/show panels with controls depending on what TreeView node the user clicks (for large data inputs), but it doesn't work and I have no idea why not. This is my code for the TreeView's AfterSelect event:

    private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
    {
    {
    if (treeView1.SelectedNode == null)
    {
    this.Text = "null";
    }
    else
    {
    if (treeView1.SelectedNode.Name == "Node1")
    {
    panel2.Visible = false;
    panel1.Visible = true;
    this.Text = "panel1 + | panel2 -";
    }
    else if (treeView1.SelectedNode.Name == "Node2")
    {
    panel1.Visible = false;
    panel2.Visible = true; //this does nothing?
    this.Text = "panel1 - | panel2 +";
    }
    }

            }
    

    By changing the form text I confirmed that the event gets properly thrown and by stepping through the code I found out that if Node2 is selected, the panel2.Visible = true line does absolutely nothing and afterwards Visible is still false. Why does that happen? I'm really confused. Thanks.

    L D T M 4 Replies Last reply
    0
    • M Megidolaon

      I try to hide/show panels with controls depending on what TreeView node the user clicks (for large data inputs), but it doesn't work and I have no idea why not. This is my code for the TreeView's AfterSelect event:

      private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
      {
      {
      if (treeView1.SelectedNode == null)
      {
      this.Text = "null";
      }
      else
      {
      if (treeView1.SelectedNode.Name == "Node1")
      {
      panel2.Visible = false;
      panel1.Visible = true;
      this.Text = "panel1 + | panel2 -";
      }
      else if (treeView1.SelectedNode.Name == "Node2")
      {
      panel1.Visible = false;
      panel2.Visible = true; //this does nothing?
      this.Text = "panel1 - | panel2 +";
      }
      }

              }
      

      By changing the form text I confirmed that the event gets properly thrown and by stepping through the code I found out that if Node2 is selected, the panel2.Visible = true line does absolutely nothing and afterwards Visible is still false. Why does that happen? I'm really confused. Thanks.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      I created a test project with a TreeView, some Nodes, and two Panels; your code works fine for me. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      1 Reply Last reply
      0
      • M Megidolaon

        I try to hide/show panels with controls depending on what TreeView node the user clicks (for large data inputs), but it doesn't work and I have no idea why not. This is my code for the TreeView's AfterSelect event:

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
        {
        if (treeView1.SelectedNode == null)
        {
        this.Text = "null";
        }
        else
        {
        if (treeView1.SelectedNode.Name == "Node1")
        {
        panel2.Visible = false;
        panel1.Visible = true;
        this.Text = "panel1 + | panel2 -";
        }
        else if (treeView1.SelectedNode.Name == "Node2")
        {
        panel1.Visible = false;
        panel2.Visible = true; //this does nothing?
        this.Text = "panel1 - | panel2 +";
        }
        }

                }
        

        By changing the form text I confirmed that the event gets properly thrown and by stepping through the code I found out that if Node2 is selected, the panel2.Visible = true line does absolutely nothing and afterwards Visible is still false. Why does that happen? I'm really confused. Thanks.

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        This stuff would work just fine, provided the controls and panels are layed out properly.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        1 Reply Last reply
        0
        • M Megidolaon

          I try to hide/show panels with controls depending on what TreeView node the user clicks (for large data inputs), but it doesn't work and I have no idea why not. This is my code for the TreeView's AfterSelect event:

          private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
          {
          {
          if (treeView1.SelectedNode == null)
          {
          this.Text = "null";
          }
          else
          {
          if (treeView1.SelectedNode.Name == "Node1")
          {
          panel2.Visible = false;
          panel1.Visible = true;
          this.Text = "panel1 + | panel2 -";
          }
          else if (treeView1.SelectedNode.Name == "Node2")
          {
          panel1.Visible = false;
          panel2.Visible = true; //this does nothing?
          this.Text = "panel1 - | panel2 +";
          }
          }

                  }
          

          By changing the form text I confirmed that the event gets properly thrown and by stepping through the code I found out that if Node2 is selected, the panel2.Visible = true line does absolutely nothing and afterwards Visible is still false. Why does that happen? I'm really confused. Thanks.

          T Offline
          T Offline
          The Man from U N C L E
          wrote on last edited by
          #4

          Sounds like Panel2 is hidden behind something else, or possibly not even added to the form correctly

          If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

          1 Reply Last reply
          0
          • M Megidolaon

            I try to hide/show panels with controls depending on what TreeView node the user clicks (for large data inputs), but it doesn't work and I have no idea why not. This is my code for the TreeView's AfterSelect event:

            private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
            {
            {
            if (treeView1.SelectedNode == null)
            {
            this.Text = "null";
            }
            else
            {
            if (treeView1.SelectedNode.Name == "Node1")
            {
            panel2.Visible = false;
            panel1.Visible = true;
            this.Text = "panel1 + | panel2 -";
            }
            else if (treeView1.SelectedNode.Name == "Node2")
            {
            panel1.Visible = false;
            panel2.Visible = true; //this does nothing?
            this.Text = "panel1 - | panel2 +";
            }
            }

                    }
            

            By changing the form text I confirmed that the event gets properly thrown and by stepping through the code I found out that if Node2 is selected, the panel2.Visible = true line does absolutely nothing and afterwards Visible is still false. Why does that happen? I'm really confused. Thanks.

            M Offline
            M Offline
            Megidolaon
            wrote on last edited by
            #5

            Apparently it didn't work because I had one panel over the other. But that is the entire point of this. Instead of putting a ton of controls next to each other or in TapControls, I want them to appear and disappear at the same location. How do I do that?

            OriginalGriffO L 2 Replies Last reply
            0
            • M Megidolaon

              Apparently it didn't work because I had one panel over the other. But that is the entire point of this. Instead of putting a ton of controls next to each other or in TapControls, I want them to appear and disappear at the same location. How do I do that?

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              Megidolaon wrote:

              Apparently it didn't work because I had one panel over the other.

              It's not that at all. Let me run through the sequence of events you went through to construct this: 1) create two panels, one above the other. (could be side by side, I dunno). 2) Put controls on each panel. 3) Drag one panel over the other so they are in the same place. Now, when you make one visible and one invisible, you see one panel. When you make that panel invisibile, and the other visible, you see no panels. This is because when you dragged one panel onto the other it became a child of the panel you dropped it on. So when you make the master panel invisible, you hide all it's children - including the other panel. Leave them separate, and move them with your code in the form load event. It'll work now... Or better, use a TabControl instead of panels...it is a lot easier to maintain in the designer! :-D

              Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              1 Reply Last reply
              0
              • M Megidolaon

                Apparently it didn't work because I had one panel over the other. But that is the entire point of this. Instead of putting a ton of controls next to each other or in TapControls, I want them to appear and disappear at the same location. How do I do that?

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                as Griff said, you probably have one of the panels containing the other. There are many ways not to do that, here is one I use sometimes: - inside Visual Designer, add first panel, smaller than intended; - now add second panel next to the first one, also smaller than intended; - so far you made sure they both belong to the Form directly; - now select one, look for the Properties pane, and adjust the Location and Size properties by editing the numbers (watch the result each time you leave the property's value field); - then select the second one (if not visible, since overlapped by the other one, use the combobox in the properties pane), and give it the appropriate (maybe the same) values for Location and Size. The net result is you only see one of the panels in Designer, however you will see one or the other at run-time. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                M 1 Reply Last reply
                0
                • L Luc Pattyn

                  as Griff said, you probably have one of the panels containing the other. There are many ways not to do that, here is one I use sometimes: - inside Visual Designer, add first panel, smaller than intended; - now add second panel next to the first one, also smaller than intended; - so far you made sure they both belong to the Form directly; - now select one, look for the Properties pane, and adjust the Location and Size properties by editing the numbers (watch the result each time you leave the property's value field); - then select the second one (if not visible, since overlapped by the other one, use the combobox in the properties pane), and give it the appropriate (maybe the same) values for Location and Size. The net result is you only see one of the panels in Designer, however you will see one or the other at run-time. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                  M Offline
                  M Offline
                  Megidolaon
                  wrote on last edited by
                  #8

                  Thanks. I didn't notice I had made panel2 the child of panel1 cause a single mm off and they were still independent. But changing locations works great. In the Visual Designer I have the panels next to each other and just overlay them at runtime like this:

                  panel2.Location = new Point(panel1.Location.X, panel1.Location.Y);

                  I still need to test how this works with the many different controls needed on other forms. After all the point of this is to switch from a huge cluster**** of nested tab controls to a more intuitive and easier usable design like for example VS options.

                  L 1 Reply Last reply
                  0
                  • M Megidolaon

                    Thanks. I didn't notice I had made panel2 the child of panel1 cause a single mm off and they were still independent. But changing locations works great. In the Visual Designer I have the panels next to each other and just overlay them at runtime like this:

                    panel2.Location = new Point(panel1.Location.X, panel1.Location.Y);

                    I still need to test how this works with the many different controls needed on other forms. After all the point of this is to switch from a huge cluster**** of nested tab controls to a more intuitive and easier usable design like for example VS options.

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #9

                    If the Form is going to show mostly text, I tend to create the structured parts by run-time code, i.e. code I write myself, as opposed to me doing repetitive sequences of point-and-click operations inside Visual Designer. You could easily write a method that adds a Panel holding some TextBoxes/ListBoxes/TreeViews/whatever, positioning them, setting their Anchors/Docks, etc. Then call that method over and over. Some advantages: it becomes easier to change your mind about layout details; and you could fetch the data from some external store (file, database, ...) and make it much more dynamic. :)

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                    Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                    M 1 Reply Last reply
                    0
                    • L Luc Pattyn

                      If the Form is going to show mostly text, I tend to create the structured parts by run-time code, i.e. code I write myself, as opposed to me doing repetitive sequences of point-and-click operations inside Visual Designer. You could easily write a method that adds a Panel holding some TextBoxes/ListBoxes/TreeViews/whatever, positioning them, setting their Anchors/Docks, etc. Then call that method over and over. Some advantages: it becomes easier to change your mind about layout details; and you could fetch the data from some external store (file, database, ...) and make it much more dynamic. :)

                      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                      M Offline
                      M Offline
                      Megidolaon
                      wrote on last edited by
                      #10

                      Nah, it's not that much to do. But I tested it now with a form that has many controls for data input and it works like a charm. In the designer it's a huge form with all panels side by side for easy editing and the first thing I do when the form is constructed is change the size and hide all panels. Then I display the appropriate panel when selecting a node and hide all others.

                      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