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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. To Dock or not to Dock? Whether tis nobler to Anchor instead?

To Dock or not to Dock? Whether tis nobler to Anchor instead?

Scheduled Pinned Locked Moved C#
questioncsharpdesign
3 Posts 3 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.
  • A Offline
    A Offline
    Al Gardner
    wrote on last edited by
    #1

    When I initially started .Net Forms I was gladdened by the provision of the Dock property and used it everywhere in resizable forms. It saved all the layout functionality that used to have be written in the Resize event from VB. However there were occasions when I would have to Dock a Panel in the form with a padding and then dock other controls inside that to get the right look and feel. So then you look a little closer at the .Net offerings and discover that you can avoid these extra controls by using Anchor instead. My question is one of developer choice. Is there a preferred method out there that people are using to layout their UI's? Does anyone favour Anchor over Dock?

    M H 2 Replies Last reply
    0
    • A Al Gardner

      When I initially started .Net Forms I was gladdened by the provision of the Dock property and used it everywhere in resizable forms. It saved all the layout functionality that used to have be written in the Resize event from VB. However there were occasions when I would have to Dock a Panel in the form with a padding and then dock other controls inside that to get the right look and feel. So then you look a little closer at the .Net offerings and discover that you can avoid these extra controls by using Anchor instead. My question is one of developer choice. Is there a preferred method out there that people are using to layout their UI's? Does anyone favour Anchor over Dock?

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      I used to prefer anchoring controls (people with a Java background might prefer docking :)), but meanwhile mostly converted. The reason was that with visual inheritance you'll get weird/incorrect results when you anchor a control to the right or lower border of the container and this container is resized in a derived form. That's why I try to use docking now wherever I can. mav

      1 Reply Last reply
      0
      • A Al Gardner

        When I initially started .Net Forms I was gladdened by the provision of the Dock property and used it everywhere in resizable forms. It saved all the layout functionality that used to have be written in the Resize event from VB. However there were occasions when I would have to Dock a Panel in the form with a padding and then dock other controls inside that to get the right look and feel. So then you look a little closer at the .Net offerings and discover that you can avoid these extra controls by using Anchor instead. My question is one of developer choice. Is there a preferred method out there that people are using to layout their UI's? Does anyone favour Anchor over Dock?

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        You should not base your usage of Dock vs. Anchor on preference, but requirements. Dock and Anchor do two different things, but they can seem similar when you anchor opposing sides. It's the ability to anchor adjecent sides that makes the two unique. If you want a Button to always stay in the lower-right corner, you anchor it to the bottom and right sides. You can't do that with docking. All you can do is dock to the bottom, but that will also work like anchoring it to the left side in addition. What you're left with doing is using a complex hierarchy of controls like the Panel or other container controls to support this. The extra window handles to track - not to mention the extra memory for these controls - is not required. Also, some container controls allow you to set the padding for docked child controls, but this still doesn't afford you the same level of control for anchoring. You can anchor a control 8 pixels from the left edge of a parent control and 16 pixels from the top, and it will stay there (for example, depending on the anchored sides). With docking, that is much more difficult. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles]

        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