none
Change the size of controls dynamically when the form size changed

    Question

  • Dear all,

    I want to ask one c# application question about the resize of the page. I can control the location of the controls in the page using the Anchor property but my question is how to control the size of the control. How can I make the control size changed automatically whenever the page size is changed? Is there any way to do so?

    Thank you and regards.

    BR//

    Monday, February 18, 2013 6:36 AM

Answers

  • > I know how to use the Anchor property and ... it will change the location automatically

    But did you know that you can Anchor a Control to more than two sides?

    using System.Windows.Forms ; 
    
    this.TextBox1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom ; 
    

    This textbox will "track" all fours sides of the form (or container Control) automatically. 



    Regards, Phill W.

    Wednesday, February 20, 2013 1:57 PM

All replies

  • In the Form Resize event handler, add the control sizing logic that will dynamically change the size of the controls. Use calculation logic to determine the unit at which the controls has to be resized proportionate to the form size.

    It all Happenz Sendil

    Monday, February 18, 2013 7:08 AM
  • Hi Abo.Ahmad,

    Simple idea is use of table layout panel with dock property set to fill but, it depends on your overall UI and logic. some people use form resize event to set there UI. Some people use simple maths to reposition there controls and change the size of controls.

    For more information on dock and Anchor properties please visit below link

    http://www.techrepublic.com/article/manage-winform-controls-using-the-anchor-and-dock-properties/6165908

    may be it helps you.
    If anything is unclear feel free to ask me... :)

    Thanks,
    Nans11


    ENjoy ThE WorLD Of COdE

    Monday, February 18, 2013 7:10 AM
  • Dear Nans,

    I know how to use the Anchor property and I find it very useful since it will change the location automatically according the size of the page. Now, my concern is changing the size of controls (such as textbox and datagrid) automatically whenever the user will increase or decrease the form size. Programming all the events is little complicated and finding good factor in which you will multiply with it whenever the user will increase or decrease the size is little difficult since it might have problem. Specially in my program, I am using photo as background and whenever the size is changed I need the control to adapt to it.

    Any other idea would really be helpful.

    Thank you and regards.

    BR//

    Monday, February 18, 2013 7:42 AM
  • Hi Abo.Ahmed,

    From your description, I ‘d like to move this post to  the most related forum.

    There are more  experts in this aspect, so you will get  better support and  may have more luck getting answers.

    Thanks for your understanding.

    Regards,


    Lisa Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, February 20, 2013 1:59 AM
  • > I know how to use the Anchor property and ... it will change the location automatically

    But did you know that you can Anchor a Control to more than two sides?

    using System.Windows.Forms ; 
    
    this.TextBox1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom ; 
    

    This textbox will "track" all fours sides of the form (or container Control) automatically. 



    Regards, Phill W.

    Wednesday, February 20, 2013 1:57 PM