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. Problem with panels

Problem with panels

Scheduled Pinned Locked Moved C#
questionhelptutorial
11 Posts 4 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.
  • N Offline
    N Offline
    nighttrain_
    wrote on last edited by
    #1

    Hi there all ! In my windows form application i add a tollstrip and 4 buttons on it. I also add 4 panels on form on Dock property: Fill. Mayby it's lame question but I want to modify some of this 4 panels and i go in properties and check for example Panel2 - the list of properties of this control is available but on form i still see a panel1, how i can see my panel2, or 3? I just want to add to this panels some buttons etc... best regards

    L OriginalGriffO B 3 Replies Last reply
    0
    • N nighttrain_

      Hi there all ! In my windows form application i add a tollstrip and 4 buttons on it. I also add 4 panels on form on Dock property: Fill. Mayby it's lame question but I want to modify some of this 4 panels and i go in properties and check for example Panel2 - the list of properties of this control is available but on form i still see a panel1, how i can see my panel2, or 3? I just want to add to this panels some buttons etc... best regards

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

      If you add several Controls to a Form and give them all DockStyle.Fill, they will overlap and only one at a time will be visible. What you can do is this: - in Visual Designer click/select one of the Controls or the Form itself; - now open the properties pane, it will show the properties for that control; - on the top it also has a ComboBox listing all the Controls of the Form; select the one you want, I expect that suffices to make it visible. :)

      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      OriginalGriffO 1 Reply Last reply
      0
      • N nighttrain_

        Hi there all ! In my windows form application i add a tollstrip and 4 buttons on it. I also add 4 panels on form on Dock property: Fill. Mayby it's lame question but I want to modify some of this 4 panels and i go in properties and check for example Panel2 - the list of properties of this control is available but on form i still see a panel1, how i can see my panel2, or 3? I just want to add to this panels some buttons etc... best regards

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

        Nope: it doesn't work like that. When you select "Dock...Fill" the panel covers the entire client area, and will re-size itself to make sure it always does. If you have multiple controls that are all set to Fill, then tehy are all teh same size, and stacked behind each other. The only way to see them at run time is to make three of them Visible=False and one of them Visible=True At Design time, they are also stacked up, only you can't make them invisible. The only way I know to select a specific panel is to use the drop down list at the top of the Properties window. Even that won't let you select panel1 and drop controls on it if panel 2 is on top of it. To do that, you will have to select a panel, use the "send to back" button, select a different panel, "send to back" and repeat until you have the panel you wanted. An easier (and nicer for the user) approach might be to use a TabControl instead, and put each of the panels on separate tabs.

        Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

        "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

        N 1 Reply Last reply
        0
        • L Luc Pattyn

          If you add several Controls to a Form and give them all DockStyle.Fill, they will overlap and only one at a time will be visible. What you can do is this: - in Visual Designer click/select one of the Controls or the Form itself; - now open the properties pane, it will show the properties for that control; - on the top it also has a ComboBox listing all the Controls of the Form; select the one you want, I expect that suffices to make it visible. :)

          Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

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

          Luc Pattyn wrote:

          I expect that suffices to make it visible.

          Unfortunately not. You have to play silly beggars with the "Bring to front" / "Send to back" buttons to do anything useful (like drop controls on them). Certainly this is the case in VS2008 - I haven't tried it in VS2010. :laugh:

          Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

          "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

          L 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Nope: it doesn't work like that. When you select "Dock...Fill" the panel covers the entire client area, and will re-size itself to make sure it always does. If you have multiple controls that are all set to Fill, then tehy are all teh same size, and stacked behind each other. The only way to see them at run time is to make three of them Visible=False and one of them Visible=True At Design time, they are also stacked up, only you can't make them invisible. The only way I know to select a specific panel is to use the drop down list at the top of the Properties window. Even that won't let you select panel1 and drop controls on it if panel 2 is on top of it. To do that, you will have to select a panel, use the "send to back" button, select a different panel, "send to back" and repeat until you have the panel you wanted. An easier (and nicer for the user) approach might be to use a TabControl instead, and put each of the panels on separate tabs.

            Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

            N Offline
            N Offline
            nighttrain_
            wrote on last edited by
            #5

            Thanks for help i did a similar but i take 3 panels and set to dock: fill and I made sure that's not any one panel is child of the other panel... So i set all panels are on Form1. Then if i want to modify some panel i used Format -> Order -> Bring to front then i have access to a panel which i want to modify... I also type those 3 panels on

            visible = false

            and

                private void toolStripSplitButton2\_ButtonClick(object sender, EventArgs e)
                {
                    panel2.Visible = false;
                    panel3.Visible = false;
                    panel1.Visible = true;
                }
            
                private void toolStripButton1\_Click(object sender, EventArgs e)
                {
                    panel2.Visible = true;
                    panel1.Visible = false;
                    panel3.Visible = false;         
                }
            
                private void toolStripButton2\_Click(object sender, EventArgs e)
                {
                    panel3.Visible = true;
                    panel1.Visible = false;
                    panel2.Visible = false;      
                }
            

            so it's that good in code? Or should i some change?

            OriginalGriffO 1 Reply Last reply
            0
            • N nighttrain_

              Thanks for help i did a similar but i take 3 panels and set to dock: fill and I made sure that's not any one panel is child of the other panel... So i set all panels are on Form1. Then if i want to modify some panel i used Format -> Order -> Bring to front then i have access to a panel which i want to modify... I also type those 3 panels on

              visible = false

              and

                  private void toolStripSplitButton2\_ButtonClick(object sender, EventArgs e)
                  {
                      panel2.Visible = false;
                      panel3.Visible = false;
                      panel1.Visible = true;
                  }
              
                  private void toolStripButton1\_Click(object sender, EventArgs e)
                  {
                      panel2.Visible = true;
                      panel1.Visible = false;
                      panel3.Visible = false;         
                  }
              
                  private void toolStripButton2\_Click(object sender, EventArgs e)
                  {
                      panel3.Visible = true;
                      panel1.Visible = false;
                      panel2.Visible = false;      
                  }
              

              so it's that good in code? Or should i some change?

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

              It's clear enough! I would be tempted to have a generic routine which sets them all invisible and then set only the one I want visible though:

                  private void toolStripSplitButton2\_ButtonClick(object sender, EventArgs e)
                  {
                      SetVisible(panel1);
                  }
              
                  private void toolStripButton1\_Click(object sender, EventArgs e)
                  {
                      SetVisible(panel2);
                  }
              
                  private void toolStripButton2\_Click(object sender, EventArgs e)
                  {
                      SetVisible(panel3);
                  }
              
                  private void SetVisible(Panel p)
                  {
                      panel1.Visible = false;
                      panel2.Visible = false;      
                      panel3.Visible = false;
                      p.Visible = true;
                  }
              

              For just three panels, I would be happy enough with that: to go any higher, I would use a loop instead:

                  private void SetVisible(Panel p)
                  {
                      foreach (Control c in Controls)
                      {
                          Panel pan = c as Panel;
                          if (pan != null)
                          {
                              pan.Visible = false;
                          }
                      }
                      p.Visible = true;
                  }
              

              Oh, and I would get rid off your names! Don't use "panel1", "panel2", "tool_stripButton2" etc.: use names that describe what they contain. "panColors" and "panFonts", "tsbSelectColors" and "tsbSelectFonts" help the readability of your code a lot, and that makes it easier to debug and work with.

              Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

              "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

              N 1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                Luc Pattyn wrote:

                I expect that suffices to make it visible.

                Unfortunately not. You have to play silly beggars with the "Bring to front" / "Send to back" buttons to do anything useful (like drop controls on them). Certainly this is the case in VS2008 - I haven't tried it in VS2010. :laugh:

                Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

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

                Tried it in VS2008, and you're right. :thumbsup:

                Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  It's clear enough! I would be tempted to have a generic routine which sets them all invisible and then set only the one I want visible though:

                      private void toolStripSplitButton2\_ButtonClick(object sender, EventArgs e)
                      {
                          SetVisible(panel1);
                      }
                  
                      private void toolStripButton1\_Click(object sender, EventArgs e)
                      {
                          SetVisible(panel2);
                      }
                  
                      private void toolStripButton2\_Click(object sender, EventArgs e)
                      {
                          SetVisible(panel3);
                      }
                  
                      private void SetVisible(Panel p)
                      {
                          panel1.Visible = false;
                          panel2.Visible = false;      
                          panel3.Visible = false;
                          p.Visible = true;
                      }
                  

                  For just three panels, I would be happy enough with that: to go any higher, I would use a loop instead:

                      private void SetVisible(Panel p)
                      {
                          foreach (Control c in Controls)
                          {
                              Panel pan = c as Panel;
                              if (pan != null)
                              {
                                  pan.Visible = false;
                              }
                          }
                          p.Visible = true;
                      }
                  

                  Oh, and I would get rid off your names! Don't use "panel1", "panel2", "tool_stripButton2" etc.: use names that describe what they contain. "panColors" and "panFonts", "tsbSelectColors" and "tsbSelectFonts" help the readability of your code a lot, and that makes it easier to debug and work with.

                  Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

                  N Offline
                  N Offline
                  nighttrain_
                  wrote on last edited by
                  #8

                  ok i rename it all and put thise code :

                  private void toolStripSplitButton2_ButtonClick(object sender, EventArgs e)
                  {
                  SetVisible(panel1);
                  }

                      private void toolStripButton1\_Click(object sender, EventArgs e)
                      {
                          SetVisible(panel2);
                      }
                  
                      private void toolStripButton2\_Click(object sender, EventArgs e)
                      {
                          SetVisible(panel3);
                      }
                  
                  
                      private void SetVisible(Panel p)
                      {
                          foreach (Control c in Controls)
                          {
                              Panel pan = c as Panel;
                              if (pan != null)
                              {
                                  pan.Visible = false;
                              }
                          }
                          p.Visible = true;
                      }
                  

                  it's more beauty of code... than set all false/true without the intended purpose if the panels will... :) P.S It's really uncomfortable to switch between all panels "bring to front" :) thx for help !!

                  OriginalGriffO 1 Reply Last reply
                  0
                  • N nighttrain_

                    ok i rename it all and put thise code :

                    private void toolStripSplitButton2_ButtonClick(object sender, EventArgs e)
                    {
                    SetVisible(panel1);
                    }

                        private void toolStripButton1\_Click(object sender, EventArgs e)
                        {
                            SetVisible(panel2);
                        }
                    
                        private void toolStripButton2\_Click(object sender, EventArgs e)
                        {
                            SetVisible(panel3);
                        }
                    
                    
                        private void SetVisible(Panel p)
                        {
                            foreach (Control c in Controls)
                            {
                                Panel pan = c as Panel;
                                if (pan != null)
                                {
                                    pan.Visible = false;
                                }
                            }
                            p.Visible = true;
                        }
                    

                    it's more beauty of code... than set all false/true without the intended purpose if the panels will... :) P.S It's really uncomfortable to switch between all panels "bring to front" :) thx for help !!

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

                    nighttrain1 wrote:

                    P.S It's really uncomfortable to switch between all panels "bring to front

                    Ain't that the truth! :laugh: That's partly why I prefer the TabControl approach.

                    nighttrain1 wrote:

                    thx for help

                    You're welcome!

                    Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

                    "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

                    N 1 Reply Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      nighttrain1 wrote:

                      P.S It's really uncomfortable to switch between all panels "bring to front

                      Ain't that the truth! :laugh: That's partly why I prefer the TabControl approach.

                      nighttrain1 wrote:

                      thx for help

                      You're welcome!

                      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

                      N Offline
                      N Offline
                      nighttrain_
                      wrote on last edited by
                      #10

                      "hehe" :D thx again

                      1 Reply Last reply
                      0
                      • N nighttrain_

                        Hi there all ! In my windows form application i add a tollstrip and 4 buttons on it. I also add 4 panels on form on Dock property: Fill. Mayby it's lame question but I want to modify some of this 4 panels and i go in properties and check for example Panel2 - the list of properties of this control is available but on form i still see a panel1, how i can see my panel2, or 3? I just want to add to this panels some buttons etc... best regards

                        B Offline
                        B Offline
                        Bassio
                        wrote on last edited by
                        #11

                        If you want to add several controls(panels in your case) to the same form and Dock them all as Fill, below is the best solution: - Add Custom user controls to your Project, each of them containing one of the panels. - Add these controls to your form and dock them as Fill. Now if you want to edit one of the panels, simply edit the custom user control you created ;)

                        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