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
but I cannot see where I'm going wrong. Any help would be appreciated.vb.net Code:
Dim PercentageWidth As Double = (Me.Width - iOrigFormWidth) / 100 Dim PercentageHeight As Double = (Me.Height - iOrigFormHeight) / 100
original sizevb.net Code:
Private Sub frmPhoneme_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load iOrigFormWidth = Me.Width iorigformheight = Me.Height Dim indx As Integer = 0 For Each ctrl As Control In Me.Controls ctrls(indx, 0) = ctrl.Top ctrls(indx, 1) = ctrl.Left ctrls(indx, 2) = ctrl.Height ctrls(indx, 3) = ctrl.Width indx += 1 Next End Sub Private Sub frmPhoneme_ResizeEnd(sender As Object, e As System.EventArgs) Handles Me.ResizeEnd Dim PercentageWidth As Double = (Me.Width - iOrigFormWidth) / 100 Dim PercentageHeight As Double = (Me.Height - iOrigFormHeight) / 100 Dim indx As Integer = 0 For Each ctrl As Control In Me.Controls ctrl.Top = CInt(ctrls(indx, 0) + (ctrls(indx, 0) * PercentageHeight)) ctrl.Left = CInt(ctrls(indx, 1) + (ctrls(indx, 1) * PercentageWidth)) ctrl.Height = CInt(ctrls(indx, 2) + (ctrls(indx, 2) * PercentageHeight)) ctrl.Width = CInt(ctrls(indx, 3) + (ctrls(indx, 3) * PercentageWidth)) indx += 1 Next End Sub
Attachment 96697
stretched
Attachment 96699
Shrunk
Attachment 96701




Reply With Quote