Click here to Skip to main content
15,922,427 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
My problem is that i am unable to resize the form control according to the form size.
I have a form which contains a textbox,a label and a button.On button click i need to open the same form in a particular size and i want all the controls of the form should be proportion with the form and the font inside the control should also in proportion.Can any one please suggest how to do that with code.Unable to solve this by using the anchor and dock property.My code

Private Sub Test_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim widthRatio As Single = Me.Size.Width / 300.0F
        Dim heightRatio As Single = Me.Size.Height / 300.0F
        Dim scale As New SizeF(widthRatio, heightRatio)
        For Each control As Control In Me.Controls
            control.Font = New Font(control.Font.FontFamily,   control.Font.SizeInPoints * widthRatio * heightRatio)
    End Sub

here for width and height ration i have divided 300.0F because my original form is size(300,300),but here am not getting all the controls expand equally..
any suggestion is appreciated.

Updated 15-Oct-12 20:58pm

1 solution

Why you are doing this much of code? Just Use Anchor Property of each control and set it to Top, Left Right, Bottom. It will do what you want to do.
Share this answer
pallavi Praharaj 16-Oct-12 4:31am    
anchor property is not working over here.i want to open a form of particular size on button click and the control should should be in same proportion.and the font of thr control should also in same proportion..anchor is not working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900