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. Other Discussions
  3. The Weird and The Wonderful
  4. Docking and Anchoring

Docking and Anchoring

Scheduled Pinned Locked Moved The Weird and The Wonderful
comdebugginghelpquestionlearning
4 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.
  • A Offline
    A Offline
    Alan N
    wrote on last edited by
    #1

    Control docking and anchoring are well understood by everybody and we all know that the two techniques are mutally exclusive. The help pages says something like "Only one can be set at a time, and the last one set takes precedence". I've always believed what I'm told by my elders and betters and was certain that code like the following would create an anchored control.

    FancyControl fc = new FancyControl();
    fc.Anchor = AnchorStyles.Top | AnchorStyles.Left;
    SomePanel.Controls.Add(fc);

    My FancyControl would typically be used fully docked and the constructor helpfully presets that condition. On the very rare occasion it should be anchored then just assign a value as shown. Why oh why then, did the control remained dicked?

    FancyControl fc = new FancyControl();
    Debug.Print("Dock: {0} Anchor: {1}", fc.Dock, fc.Anchor);
    // Dock: Fill Anchor: Top, Left
    fc.Anchor = AnchorStyles.Top | AnchorStyles.Left;
    SomePanel.Controls.Add(fc);

    On reading the Anchor property all became clear as the value was already Top|Left. Perhaps the Anchor property ignores redundant assignments? Of course it does and a delve into the published reference source confirms this. Search for DefaultLayout.SetAnchor in Reference Source[^] if you are interested. The final solution for the simple task of setting the control's anchor property is

    FancyControl fc = new FancyControl();
    fc.Dock = DockStyle.None;
    SomePanel.Controls.Add(fc);

    OK I should have included the statement fc.Anchor = AnchorStyles.Top | AnchorStyles.Left; after undocking but it's redundant! AlanN aka Alan "2f hours debugging" N

    M C 2 Replies Last reply
    0
    • A Alan N

      Control docking and anchoring are well understood by everybody and we all know that the two techniques are mutally exclusive. The help pages says something like "Only one can be set at a time, and the last one set takes precedence". I've always believed what I'm told by my elders and betters and was certain that code like the following would create an anchored control.

      FancyControl fc = new FancyControl();
      fc.Anchor = AnchorStyles.Top | AnchorStyles.Left;
      SomePanel.Controls.Add(fc);

      My FancyControl would typically be used fully docked and the constructor helpfully presets that condition. On the very rare occasion it should be anchored then just assign a value as shown. Why oh why then, did the control remained dicked?

      FancyControl fc = new FancyControl();
      Debug.Print("Dock: {0} Anchor: {1}", fc.Dock, fc.Anchor);
      // Dock: Fill Anchor: Top, Left
      fc.Anchor = AnchorStyles.Top | AnchorStyles.Left;
      SomePanel.Controls.Add(fc);

      On reading the Anchor property all became clear as the value was already Top|Left. Perhaps the Anchor property ignores redundant assignments? Of course it does and a delve into the published reference source confirms this. Search for DefaultLayout.SetAnchor in Reference Source[^] if you are interested. The final solution for the simple task of setting the control's anchor property is

      FancyControl fc = new FancyControl();
      fc.Dock = DockStyle.None;
      SomePanel.Controls.Add(fc);

      OK I should have included the statement fc.Anchor = AnchorStyles.Top | AnchorStyles.Left; after undocking but it's redundant! AlanN aka Alan "2f hours debugging" N

      M Offline
      M Offline
      Marc Clifton
      wrote on last edited by
      #2

      Alan N wrote:

      did the control remained dicked?

      Is that gender-specific control property? ;) Marc

      Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project! Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny

      T 1 Reply Last reply
      0
      • M Marc Clifton

        Alan N wrote:

        did the control remained dicked?

        Is that gender-specific control property? ;) Marc

        Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project! Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny

        T Offline
        T Offline
        TheGreatAndPowerfulOz
        wrote on last edited by
        #3

        No, having a dick does not imply gender at all these days. :rolleyes:

        #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

        1 Reply Last reply
        0
        • A Alan N

          Control docking and anchoring are well understood by everybody and we all know that the two techniques are mutally exclusive. The help pages says something like "Only one can be set at a time, and the last one set takes precedence". I've always believed what I'm told by my elders and betters and was certain that code like the following would create an anchored control.

          FancyControl fc = new FancyControl();
          fc.Anchor = AnchorStyles.Top | AnchorStyles.Left;
          SomePanel.Controls.Add(fc);

          My FancyControl would typically be used fully docked and the constructor helpfully presets that condition. On the very rare occasion it should be anchored then just assign a value as shown. Why oh why then, did the control remained dicked?

          FancyControl fc = new FancyControl();
          Debug.Print("Dock: {0} Anchor: {1}", fc.Dock, fc.Anchor);
          // Dock: Fill Anchor: Top, Left
          fc.Anchor = AnchorStyles.Top | AnchorStyles.Left;
          SomePanel.Controls.Add(fc);

          On reading the Anchor property all became clear as the value was already Top|Left. Perhaps the Anchor property ignores redundant assignments? Of course it does and a delve into the published reference source confirms this. Search for DefaultLayout.SetAnchor in Reference Source[^] if you are interested. The final solution for the simple task of setting the control's anchor property is

          FancyControl fc = new FancyControl();
          fc.Dock = DockStyle.None;
          SomePanel.Controls.Add(fc);

          OK I should have included the statement fc.Anchor = AnchorStyles.Top | AnchorStyles.Left; after undocking but it's redundant! AlanN aka Alan "2f hours debugging" N

          C Offline
          C Offline
          Clifford Nelson
          wrote on last edited by
          #4

          Anchoring is not use in WPF. Docking is used if you use a DockPanel.

          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