Auto Resizing Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SammyB
    Recognized Expert Contributor
    • Mar 2007
    • 807

    #1

    Auto Resizing Form

    I have a form with a ToolStrip at the top and a TabControl just below it. The TabControl fills the rest of the form and has it's tabs on the right, off of the form. The click event of the ToolStripButton s selects the correct tab. Each tab page has a TableLayoutPane l that is fill-docked and contains the controls. As part of the tool strip button click event, I would like to change the height of the form to remove any empty space at the bottom of the form. Right now, I just have the height for each page hard coded, but I would like to iterate thru the current TableLayoutPane l.Controls, find the bottom-most control, and use that control's Bottom property to set the form height.

    I can do all of that except setting the height correctly, because the bottom-most control location is relative to the TableLayout panel. How can I translate this into a form location? TIA --Sam
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Before the height thing, you say you just made your tabcontrol be large enough to shove its tabs off to the side so they are not visible? You can just turn them off with a property.

    Ok, so you want to size of the overall form to change depending on which Tab is currently visible? So if there are a lof of controls on a page (top - to - bottom) you want that the height of the form be increased, versus a tab with very few controls getting the form shrunk?

    Can you get away with just using anchors on your controls? And you don't want to go by how big you "know" the controls are, but to do it automatically?

    I am confused.

    Comment

    • SammyB
      Recognized Expert Contributor
      • Mar 2007
      • 807

      #3
      Originally posted by Plater
      Before the height thing, you say you just made your tabcontrol be large enough to shove its tabs off to the side so they are not visible? You can just turn them off with a property.
      What property? I assume it must be a framework 3.0 property. Unfortunately, I am still using framework 2.0. However, if there is one in 2.0, please let me know ASAP. It is my biggest need.

      Originally posted by Plater
      I am confused.
      Sorry, I included too many non-pertinent details. Let me start over:
      I have a complicated form with several layers of container controls. If I have a control on the form, then the Location property is relative to the parent container control. Is there an easy way to determine the location of this control relative to the form. For example, if I place a group box on a form at location (10,10) and place a label in the group box at location (5,5), then the label’s Location property is (5,5), but I would like a function that returns (15,15), the location of the control on the form.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        No, it would have been for framework 2.0 since that is what I use as well. Cannot for the life of me find it now. BUT I did find the Appearence property which turned the tabs into buttons, which gave the appearance of a toolstrip above (since that was where i had the tabs aligned to) which could also be of help? I saw ItemSize, which sets how big the tab is, but it wouldn't let me set it to zero, just (1,1)

        You could maybe make a function that take a control and goes upwards through its parent adding up the values of the location?

        Like:
        [code=c#]
        Point GetLocationOfCR elativeToP(Cont rol C, Control P)
        {
        }
        [/code]
        And work from C upwards to P (or until no more parents)


        There is a PointToScreen() function that could maybe be used to skip those steps. Get the Point location on the screen of the form and then for the control and compute the diference? That would rely on them both being visible on screen though I think

        Comment

        • SammyB
          Recognized Expert Contributor
          • Mar 2007
          • 807

          #5
          Originally posted by Plater
          Appearence property which turned the tabs into buttons, which gave the appearance of a toolstrip
          Tried that, but I like the toolstrip better

          Originally posted by Plater
          saw ItemSize, which sets how big the tab is, but it wouldn't let me set it to zero, just (1,1)
          This is perfect! I set the Dock to Fill, Alignment to Right, SizeMode to Fixed, and ItemSize to (15,15). This allows me to switch tabs in the design mode. Then, in the FormLoad event, I set the ItemSize to (0,1). Presto, no tabs! Thanks!

          Originally posted by Plater
          There is a PointToScreen() function that could maybe be used to skip those steps. Get the Point location on the screen of the form and then for the control and compute the diference? That would rely on them both being visible on screen though I think
          That's what I should have done! But, I already have one working that goes upward thru the containers like your first solution.

          Thanks again for all of your help! --Sam

          Comment

          Working...