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. Docking/Anchoring controls

Docking/Anchoring controls

Scheduled Pinned Locked Moved C#
winformsdockerdata-structures
7 Posts 4 Posters 2 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.
  • E Offline
    E Offline
    Echilon
    wrote on last edited by
    #1

    I have a user control (which for the purposes of this post is just a container), and several nested user controls. I want to lay out the child controls inside the container in a similar way to the following picture: http://mi6.nu/docking.jpg I've tried different combinations of Anchor and Dock properties as well as using a Flow Layout Panel, but I can't get it to work. The two things I know are: 1) The location of each child control on the Y-axis 2) The height of the control I need some way to assign these controls a combination of properties and have them stack up as shown in the picture. Full width child controls should float to the left, and if there's more than one child control at a Y location (eg: 3 and 4), the available space should be split. I managed to get it sort of working, but items were overlapping.

    P L E 3 Replies Last reply
    0
    • E Echilon

      I have a user control (which for the purposes of this post is just a container), and several nested user controls. I want to lay out the child controls inside the container in a similar way to the following picture: http://mi6.nu/docking.jpg I've tried different combinations of Anchor and Dock properties as well as using a Flow Layout Panel, but I can't get it to work. The two things I know are: 1) The location of each child control on the Y-axis 2) The height of the control I need some way to assign these controls a combination of properties and have them stack up as shown in the picture. Full width child controls should float to the left, and if there's more than one child control at a Y location (eg: 3 and 4), the available space should be split. I managed to get it sort of working, but items were overlapping.

      P Offline
      P Offline
      paas
      wrote on last edited by
      #2

      Have you looked at adding a SplitContainer into the mix? I'm thinking that if you dock one panel on the left side of the form (or control), dock a second panel in the upper-right, a third panel in the bottom right, and place a SplitContainer into an area you leave open between the two panels docked on the right, then you can place your #3 and #4 controls in the split container panels, and not worry about any overlap. You could set the IsSplitterFixed property to True to prevent the user from resizing the split, and make the splitterwidth small enough that it is unseen. Anyways, that is one idea, I won't be surprised if there are better ideas...

      1 Reply Last reply
      0
      • E Echilon

        I have a user control (which for the purposes of this post is just a container), and several nested user controls. I want to lay out the child controls inside the container in a similar way to the following picture: http://mi6.nu/docking.jpg I've tried different combinations of Anchor and Dock properties as well as using a Flow Layout Panel, but I can't get it to work. The two things I know are: 1) The location of each child control on the Y-axis 2) The height of the control I need some way to assign these controls a combination of properties and have them stack up as shown in the picture. Full width child controls should float to the left, and if there's more than one child control at a Y location (eg: 3 and 4), the available space should be split. I managed to get it sort of working, but items were overlapping.

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

        yep, do it hierarchically, i.e. split your form in two parts (that would be 1 versus 2+3+4+5) using either a SplitContainer or two Panels; give those the right anchoring. Then iterate for the next split (5 versus 2+3+4). Etc. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Voting for dummies? No thanks. X|


        1 Reply Last reply
        0
        • E Echilon

          I have a user control (which for the purposes of this post is just a container), and several nested user controls. I want to lay out the child controls inside the container in a similar way to the following picture: http://mi6.nu/docking.jpg I've tried different combinations of Anchor and Dock properties as well as using a Flow Layout Panel, but I can't get it to work. The two things I know are: 1) The location of each child control on the Y-axis 2) The height of the control I need some way to assign these controls a combination of properties and have them stack up as shown in the picture. Full width child controls should float to the left, and if there's more than one child control at a Y location (eg: 3 and 4), the available space should be split. I managed to get it sort of working, but items were overlapping.

          E Offline
          E Offline
          Echilon
          wrote on last edited by
          #4

          Thanks for the quick response. I didn't explain myself very well. The number of child controls isn't a fixed value. In the example there are two items with the same Y value, but there may be just one, or four or five.

          L D 2 Replies Last reply
          0
          • E Echilon

            Thanks for the quick response. I didn't explain myself very well. The number of child controls isn't a fixed value. In the example there are two items with the same Y value, but there may be just one, or four or five.

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

            I don't know which Control would help you split a distance in N equal parts, N being possibly larger than 2 and not a power of 2. The way I used to do all these things, before I was even aware of anchoring and SplitContainers, is by calculating Top, Left, Height and Width myself, by code, in the OnResize handler. Takes some code, but does exactly what you want with no additional Controls to achieve your layout. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            Voting for dummies? No thanks. X|


            1 Reply Last reply
            0
            • E Echilon

              Thanks for the quick response. I didn't explain myself very well. The number of child controls isn't a fixed value. In the example there are two items with the same Y value, but there may be just one, or four or five.

              D Offline
              D Offline
              DaveyM69
              wrote on last edited by
              #6

              I still do it the way that Luc mentioned in his post above. It's alot more code but it leaves you in control!

              Dave

              E 1 Reply Last reply
              0
              • D DaveyM69

                I still do it the way that Luc mentioned in his post above. It's alot more code but it leaves you in control!

                Dave

                E Offline
                E Offline
                Echilon
                wrote on last edited by
                #7

                Looks like mountains of code it is then. :-D I always try to avoid excessive code, especially in OnPaint methods, but there are times when it's unavoidable.

                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