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. It doesn't seem like resizable forms are inheritable

It doesn't seem like resizable forms are inheritable

Scheduled Pinned Locked Moved C#
questioncsharpasp-netvisual-studiodocker
11 Posts 3 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.
  • R Offline
    R Offline
    RobertSF
    wrote on last edited by
    #1

    I've recently experimented with base and derived forms, and though it works fine with non-resizable forms, there are problems with resizable forms. As you know, with resizable forms, you use anchoring and docking to keep the controls in place and let the form resize gracefully. But when you inherit from a form that has anchored or docked controls, the inherited form does not display correctly in the Visual Studio Form Designer. It appears to compile and display correctly while running, but that too could break. Obviously, in an inherited form, both constructors execute, the base form's and the derived form's. It seems the problem is that one form's constructor sets measurements while the layout is suspended in the other form's constructor. I read about this in Roland Weigelt's blog Roland Weigelt - Visual Inheritance - How to escape Layout Hell[^] He explains that

    Quote:

    In the moment the constructor of the base class is left, the layout and the controls are perfect for a Form1 instance - but that's not what we want. The method InitializeComponent() of class Form2 contains the code that is necessary to achieve the desired layout by tweaking the base form and adding the second button. While setting the Text property to "Form2" is rather trivial, setting the ClientSize property causes serious trouble. The problem is that the size is set while the layout logic is suspended; i.e. the size of the form is changed, but the anchored elements of the base class are not updated.

    And in Roland Weigelt - Visual Inheritance Revisited[^]

    Quote:

    Question: So why does docking work, but not anchoring? Docking tells a control to grab as much space as possible (for top/bottom/left/right: towards to the specified direction) until a border of the container is reached. When the size of the control's container changes, the border is moving, so the docked control will resize itself accordingly. Anchoring tells a control to keep a constant distance between a specified border (top/bottom/left/right) of the control and the corresponding border of the container at all times. Now if the container is resized while l

    L OriginalGriffO 2 Replies Last reply
    0
    • R RobertSF

      I've recently experimented with base and derived forms, and though it works fine with non-resizable forms, there are problems with resizable forms. As you know, with resizable forms, you use anchoring and docking to keep the controls in place and let the form resize gracefully. But when you inherit from a form that has anchored or docked controls, the inherited form does not display correctly in the Visual Studio Form Designer. It appears to compile and display correctly while running, but that too could break. Obviously, in an inherited form, both constructors execute, the base form's and the derived form's. It seems the problem is that one form's constructor sets measurements while the layout is suspended in the other form's constructor. I read about this in Roland Weigelt's blog Roland Weigelt - Visual Inheritance - How to escape Layout Hell[^] He explains that

      Quote:

      In the moment the constructor of the base class is left, the layout and the controls are perfect for a Form1 instance - but that's not what we want. The method InitializeComponent() of class Form2 contains the code that is necessary to achieve the desired layout by tweaking the base form and adding the second button. While setting the Text property to "Form2" is rather trivial, setting the ClientSize property causes serious trouble. The problem is that the size is set while the layout logic is suspended; i.e. the size of the form is changed, but the anchored elements of the base class are not updated.

      And in Roland Weigelt - Visual Inheritance Revisited[^]

      Quote:

      Question: So why does docking work, but not anchoring? Docking tells a control to grab as much space as possible (for top/bottom/left/right: towards to the specified direction) until a border of the container is reached. When the size of the control's container changes, the border is moving, so the docked control will resize itself accordingly. Anchoring tells a control to keep a constant distance between a specified border (top/bottom/left/right) of the control and the corresponding border of the container at all times. Now if the container is resized while l

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      So, WinForms. Might helpt a bit if you include that info.

      RobertSF wrote:

      He advises to use docked panels, but I found this not to work, probably because WinForms has changed since 2003, when he wrote that article.

      It didn't, but you found me in a non explaining mood. Did you really think that WinForms would change after these years?

      RobertSF wrote:

      Do you use form inheritance, and if so, how do you deal with this?

      Yes. And elegant.

      Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

      R 1 Reply Last reply
      0
      • L Lost User

        So, WinForms. Might helpt a bit if you include that info.

        RobertSF wrote:

        He advises to use docked panels, but I found this not to work, probably because WinForms has changed since 2003, when he wrote that article.

        It didn't, but you found me in a non explaining mood. Did you really think that WinForms would change after these years?

        RobertSF wrote:

        Do you use form inheritance, and if so, how do you deal with this?

        Yes. And elegant.

        Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

        R Offline
        R Offline
        RobertSF
        wrote on last edited by
        #3

        Sorry, and thank you. Hope your day gets better.

        L 1 Reply Last reply
        0
        • R RobertSF

          Sorry, and thank you. Hope your day gets better.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Hahaha, yeah, you do that :D You can inherit resizable forms offcourse.

          Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

          1 Reply Last reply
          0
          • R RobertSF

            I've recently experimented with base and derived forms, and though it works fine with non-resizable forms, there are problems with resizable forms. As you know, with resizable forms, you use anchoring and docking to keep the controls in place and let the form resize gracefully. But when you inherit from a form that has anchored or docked controls, the inherited form does not display correctly in the Visual Studio Form Designer. It appears to compile and display correctly while running, but that too could break. Obviously, in an inherited form, both constructors execute, the base form's and the derived form's. It seems the problem is that one form's constructor sets measurements while the layout is suspended in the other form's constructor. I read about this in Roland Weigelt's blog Roland Weigelt - Visual Inheritance - How to escape Layout Hell[^] He explains that

            Quote:

            In the moment the constructor of the base class is left, the layout and the controls are perfect for a Form1 instance - but that's not what we want. The method InitializeComponent() of class Form2 contains the code that is necessary to achieve the desired layout by tweaking the base form and adding the second button. While setting the Text property to "Form2" is rather trivial, setting the ClientSize property causes serious trouble. The problem is that the size is set while the layout logic is suspended; i.e. the size of the form is changed, but the anchored elements of the base class are not updated.

            And in Roland Weigelt - Visual Inheritance Revisited[^]

            Quote:

            Question: So why does docking work, but not anchoring? Docking tells a control to grab as much space as possible (for top/bottom/left/right: towards to the specified direction) until a border of the container is reached. When the size of the control's container changes, the border is moving, so the docked control will resize itself accordingly. Anchoring tells a control to keep a constant distance between a specified border (top/bottom/left/right) of the control and the corresponding border of the container at all times. Now if the container is resized while l

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

            I inherit from resizable WinForms quite often (mostly to provide a common "look and feel" plus I use large image buttons and fonts that all forms need - and it works well:

            public partial class FormBase : Form
                {
            

            ...
            }

            public partial class FrmMain : FormBase
                {
            

            ...
            }

            The "standard" buttons are set in FrmBase, and all derived forms include them. The only PITA for me is that the base form cannot be abstract because the designer can't cope unless you add a dummy concrete class "in the middle" for design mode only (which I hate because it means I'm not testing the same code I'll use in production). I've never had a problem with Anchoring or Docking - what exactly is happening to your derived form when you resize it?

            "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 AntiTwitter: @DalekDave is now a follower!

            "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

            R 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              I inherit from resizable WinForms quite often (mostly to provide a common "look and feel" plus I use large image buttons and fonts that all forms need - and it works well:

              public partial class FormBase : Form
                  {
              

              ...
              }

              public partial class FrmMain : FormBase
                  {
              

              ...
              }

              The "standard" buttons are set in FrmBase, and all derived forms include them. The only PITA for me is that the base form cannot be abstract because the designer can't cope unless you add a dummy concrete class "in the middle" for design mode only (which I hate because it means I'm not testing the same code I'll use in production). I've never had a problem with Anchoring or Docking - what exactly is happening to your derived form when you resize it?

              "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 AntiTwitter: @DalekDave is now a follower!

              R Offline
              R Offline
              RobertSF
              wrote on last edited by
              #6

              OriginalGriff wrote:

              I've never had a problem with Anchoring or Docking - what exactly is happening to your derived form when you resize it?

              The problem happens as soon as I derive a form from a base form. The derived form appears in the visual designer like this https://i.ibb.co/5sDNBRP/Untitled.png[^] The derived form only shows the control box. I expand the form to its proper default size, and everything looks good. When I reopen that form in the designer, however, the controls are all jumbled and out of place. Curiously, if I compile and open the form during execution, it appears fine. The blog I linked in my first post describes the problem and its causes. Thanks for the reality check. I'll upgrade my VS 2017 to the latest, and maybe it's time to move to WPF and drop WinForms. :)

              OriginalGriffO 1 Reply Last reply
              0
              • R RobertSF

                OriginalGriff wrote:

                I've never had a problem with Anchoring or Docking - what exactly is happening to your derived form when you resize it?

                The problem happens as soon as I derive a form from a base form. The derived form appears in the visual designer like this https://i.ibb.co/5sDNBRP/Untitled.png[^] The derived form only shows the control box. I expand the form to its proper default size, and everything looks good. When I reopen that form in the designer, however, the controls are all jumbled and out of place. Curiously, if I compile and open the form during execution, it appears fine. The blog I linked in my first post describes the problem and its causes. Thanks for the reality check. I'll upgrade my VS 2017 to the latest, and maybe it's time to move to WPF and drop WinForms. :)

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

                Have you tried expanding the size?

                "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 AntiTwitter: @DalekDave is now a follower!

                "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

                R 1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  Have you tried expanding the size?

                  "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 AntiTwitter: @DalekDave is now a follower!

                  R Offline
                  R Offline
                  RobertSF
                  wrote on last edited by
                  #8

                  Yes, and when expanded, the form looks fine, but after saving and reopening, then the controls are jumbled and out of place. However, I'll have to figure out what I did different because now the form reopens just fine. Thanks for your suggestions. Maybe it did solve the issue to use docked panels instead of putting the controls directly in the form. Is that a technique you use? If you have a chance, give the articles I linked a look. They're interesting, and the writer seems to know his stuff.

                  OriginalGriffO 1 Reply Last reply
                  0
                  • R RobertSF

                    Yes, and when expanded, the form looks fine, but after saving and reopening, then the controls are jumbled and out of place. However, I'll have to figure out what I did different because now the form reopens just fine. Thanks for your suggestions. Maybe it did solve the issue to use docked panels instead of putting the controls directly in the form. Is that a technique you use? If you have a chance, give the articles I linked a look. They're interesting, and the writer seems to know his stuff.

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

                    Mostly, yes - though I generally create a UserControl if it's going to fill an area like a toolbar does, or provide a status bar. Those work fine docked to the top / bottom, then I'll use a central panel to drop other controls on.

                    "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 AntiTwitter: @DalekDave is now a follower!

                    "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

                    R 1 Reply Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      Mostly, yes - though I generally create a UserControl if it's going to fill an area like a toolbar does, or provide a status bar. Those work fine docked to the top / bottom, then I'll use a central panel to drop other controls on.

                      "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 AntiTwitter: @DalekDave is now a follower!

                      R Offline
                      R Offline
                      RobertSF
                      wrote on last edited by
                      #10

                      Thanks. I think that was the issue. I must have used anchoring instead of docking. I feel a bit like Howie Mandel here. :laugh: David & Leeman: Howie Mandel Can't Read When Magicians Squeeze His Skull - America's Got Talent 2014 - YouTube[^]

                      OriginalGriffO 1 Reply Last reply
                      0
                      • R RobertSF

                        Thanks. I think that was the issue. I must have used anchoring instead of docking. I feel a bit like Howie Mandel here. :laugh: David & Leeman: Howie Mandel Can't Read When Magicians Squeeze His Skull - America's Got Talent 2014 - YouTube[^]

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

                        It can get confusing sometimes - easy mistake to make!

                        "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 AntiTwitter: @DalekDave is now a follower!

                        "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
                        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