0

Hi I utilize the below code to increase the size of all the controls of my form when the form is maximized as anchor , dock and autosize does not icrease size of the control.

Private Sub PaForm_Resize(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles Me.Resize



        If Me.WindowState = FormWindowState.Maximized Then

            count = count + 1
            If count <= 2 Then

                Dim RW As Double = (Me.Width - CW) / CW ' Ratio change of width
                Dim RH As Double = (Me.Height - CH) / CH ' Ratio change of height

                For Each Ctrl As Control In Controls

                    Ctrl.Width += CInt(Ctrl.Width * RW)
                    Ctrl.Height += CInt(Ctrl.Height * RH)

                    Ctrl.Left += CInt(Ctrl.Left * RW)
                    Ctrl.Top += CInt(Ctrl.Top * RH)
                Next

                For Each c As Control In Panel1.Controls
                    c.Width += CInt(c.Width * RW / 4)
                    c.Height += CInt(c.Height * RH / 4)
                    c.Left += CInt(c.Left * RW / 4)
                    c.Top += CInt(c.Top * RH / 4)
                Next
            End If
        End If

When i restore down the size of the controls are same and does not fit in to the window.

can you please suggest how to decrease the size and get all the controls to the normal state.

Form maximized:

enter image description here

After restore:

enter image description here

Expected:

enter image description here

Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151
user3478236
  • 1
  • 1
  • 3

2 Answers2

2

Add your controls to a TableLayoutPanel,It will resize your controls, if its dock to fill.

vipin
  • 357
  • 3
  • 9
0

It is now much easier to understand what you want, by looking at the screenshots.

In this case I agree with your first answer - start using TableLayoutPanel. For your two columns of combo boxes, you can one (width auto or fixed for labels, and % for textboxes), for A01 - H12 buttons - another one, and panel #3 for "controls OK" checkbox and the rest.

You could use one TableLayoutPanel for everything, but then will need to play with column span, and this solution is not so flexible if you decide to expand either region.

Community
  • 1
  • 1
Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151
  • DO i need to add the combox box to the tablelayout panel in run time . how do i do this during my run time @neolisk – user3478236 Aug 17 '15 at 12:05
  • @user3478236: Check this link. [Adding controls to TableLayoutPanel dynamically during runtime](http://stackoverflow.com/questions/13992429/adding-controls-to-tablelayoutpanel-dynamically-during-runtime). – Victor Zakharov Aug 17 '15 at 16:48
  • I tired the table layout panel the spacing betweent the controls is auto adjusted but the size of the controls are not increased or autosized. can you let me know how can that be done. – user3478236 Aug 18 '15 at 10:07
  • @user3478236: You need to dock the control inside table layout panel's cell. ctl.Dock = Fill. https://msdn.microsoft.com/en-us/library/system.windows.forms.dockstyle%28v=vs.110%29.aspx – Victor Zakharov Aug 18 '15 at 14:08
  • @user3478236: If my answer was helpful, don't forget to accept/upvote. – Victor Zakharov Aug 20 '15 at 10:59