locked
Control Resizing Difficulty RRS feed

  • Question

  • Environment is as follows: Windows Mobile 6.5, using .NET CF 3.5

    Probably another newbie question, however after having beat my head against the wall sufficiently:

    I have a Form, which has implemented several buttons.  I built the Form in the Designer.  My goal is to have the form resize itself to the device screen, and the buttons which have been placed on the form to resize proportionally to that new form (imagine something like a calculator keypad).  Unfortunately the button controls seem to retain their absolute size from the designer, resulting in either large buttons which cause scroll bars to appear, or very small buttons which only occupy a fraction of the real-estate of the screen.

    I have been trying various methods using properties such as ANCHOR and DOCK, but so far I haven't achieved the desired result.  I am new to WM and .NET, so I fear perhaps my understanding of these properties still isn't that great.  So, I am very open to suggestions if anyone can recommend a process by which these buttons as a whole can take up as much of the screen as possible (but not more)

    Thanks

    Wednesday, July 7, 2010 2:44 PM

Answers

  • The anchor property alone should be sufficient to resize the buttons by just anchoring each button to all four sides. This makes it so that the top of the button is always the same distance from the top of its container, the left side of the button is always the same distance from the left edge of its container, etc. 

    This approach will sometimes give a stretched out feel to the form, because for example, it will stretch the button control, but not change the button text size.  Give it a try, and see if it gives the result you are looking for.

    Docking to the top will pin your control against the top, left, and right sides of your container, and allows you to control its height.  Docking to the left will pin your control against the left, top, and bottom sides of your container, and allow you to control its width, etc.  Choosing DockingStyle.Fill will pin your control against all four sides of its container, and will not allow any manual sizing of the control.

    Docking buttons is rarely useful, if ever. It can be useful, though, to add a Panel control to your form, and dock the panel to against a side.  You can drop the buttons into the Panel control so that it becomes their container.  Then, all of the Anchor and Dock properties of the buttons you add will be relative to the Panel, and not the form.

    Please give a little more background if you can about what you are seeing.  Are you deploying to both VGA and QVGA devices, and that is where you see the sizing issues?  As far as different screen sizes go, the autoscaling should work to make most of your controls work at either resolution.  The more specifics you give about what you are trying to accomplish and the results you are seeing, the easier it will be to give specific advice.

    • Marked as answer by warrentang Monday, July 12, 2010 5:00 AM
    Wednesday, July 7, 2010 9:23 PM
  • To add on, you can also go through this code project article by Maarten Struys and Doug Turn which explains what Docking and Anchor does,

    http://www.codeproject.com/KB/windows/MOB4DEVS03.aspx

     

    Prabhu
    www.geekswithblogs.net/techtwaddle

     

    • Marked as answer by warrentang Monday, July 12, 2010 5:00 AM
    Thursday, July 8, 2010 3:58 AM

All replies

  • The anchor property alone should be sufficient to resize the buttons by just anchoring each button to all four sides. This makes it so that the top of the button is always the same distance from the top of its container, the left side of the button is always the same distance from the left edge of its container, etc. 

    This approach will sometimes give a stretched out feel to the form, because for example, it will stretch the button control, but not change the button text size.  Give it a try, and see if it gives the result you are looking for.

    Docking to the top will pin your control against the top, left, and right sides of your container, and allows you to control its height.  Docking to the left will pin your control against the left, top, and bottom sides of your container, and allow you to control its width, etc.  Choosing DockingStyle.Fill will pin your control against all four sides of its container, and will not allow any manual sizing of the control.

    Docking buttons is rarely useful, if ever. It can be useful, though, to add a Panel control to your form, and dock the panel to against a side.  You can drop the buttons into the Panel control so that it becomes their container.  Then, all of the Anchor and Dock properties of the buttons you add will be relative to the Panel, and not the form.

    Please give a little more background if you can about what you are seeing.  Are you deploying to both VGA and QVGA devices, and that is where you see the sizing issues?  As far as different screen sizes go, the autoscaling should work to make most of your controls work at either resolution.  The more specifics you give about what you are trying to accomplish and the results you are seeing, the easier it will be to give specific advice.

    • Marked as answer by warrentang Monday, July 12, 2010 5:00 AM
    Wednesday, July 7, 2010 9:23 PM
  • To add on, you can also go through this code project article by Maarten Struys and Doug Turn which explains what Docking and Anchor does,

    http://www.codeproject.com/KB/windows/MOB4DEVS03.aspx

     

    Prabhu
    www.geekswithblogs.net/techtwaddle

     

    • Marked as answer by warrentang Monday, July 12, 2010 5:00 AM
    Thursday, July 8, 2010 3:58 AM