I wanted my controls to basically "zoom" in or out as the form was resized. I tried playing with dock and anchor but the results wasn't satisfactory. Controls were resized according to the form being resized, but the top,left always remained in the same position. The result of this was that controls overlapped as they got bigger.
So, I wrote the code below which works very well except that the percentage of zoom does not tally between the form and the controls. I know that is explained badly. I have attached screenshots to illustrate the point.
I think the error is somewhere in
vb.net Code:
  1. Dim PercentageWidth As Double = (Me.Width - iOrigFormWidth) / 100
  2.         Dim PercentageHeight As Double = (Me.Height - iOrigFormHeight) / 100
but I cannot see where I'm going wrong. Any help would be appreciated.
vb.net Code:
  1. Private Sub frmPhoneme_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  2.         iOrigFormWidth = Me.Width
  3.         iorigformheight = Me.Height
  4.         Dim indx As Integer = 0
  5.         For Each ctrl As Control In Me.Controls
  6.             ctrls(indx, 0) = ctrl.Top
  7.             ctrls(indx, 1) = ctrl.Left
  8.             ctrls(indx, 2) = ctrl.Height
  9.             ctrls(indx, 3) = ctrl.Width
  10.             indx += 1
  11.         Next
  12.     End Sub
  13.  
  14.     Private Sub frmPhoneme_ResizeEnd(sender As Object, e As System.EventArgs) Handles Me.ResizeEnd
  15.         Dim PercentageWidth As Double = (Me.Width - iOrigFormWidth) / 100
  16.         Dim PercentageHeight As Double = (Me.Height - iOrigFormHeight) / 100
  17.         Dim indx As Integer = 0
  18.         For Each ctrl As Control In Me.Controls
  19.             ctrl.Top = CInt(ctrls(indx, 0) + (ctrls(indx, 0) * PercentageHeight))
  20.             ctrl.Left = CInt(ctrls(indx, 1) + (ctrls(indx, 1) * PercentageWidth))
  21.             ctrl.Height = CInt(ctrls(indx, 2) + (ctrls(indx, 2) * PercentageHeight))
  22.             ctrl.Width = CInt(ctrls(indx, 3) + (ctrls(indx, 3) * PercentageWidth))
  23.             indx += 1
  24.         Next
  25.     End Sub
original size
Attachment 96697

stretched
Attachment 96699

Shrunk
Attachment 96701