Private Sub Form1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
If Me.Width < 500 Or Me.Height < 400 Then Exit Sub 'set these values a minimums
Dim Ratio_X As Double = Me.Width / 800
Dim i, k as Integer
Me.SuspendLayout() 'this stops flickering, but does load the new form image with a flash
lvwData.BeginUpdate()
lvwData.Scrollable = True
Me.lvwData.Size = New Size(Me.Width - 8, Me.Height - 600 + 218) 'applying ratios
Me.lvwData.Columns(0).Width = 115 * Ratio_X 'Description
Me.lvwData.Columns(1).Width = 30 * Ratio_X 'Quantity
Me.lvwData.Columns(2).Width = 25 * Ratio_X 'Phase
For i = 3 To 10
If lvwData.Columns(i).Text = "Eff" Then 'special sizing rules
For k = 3 To 12
If lvwData.Columns(k).Text = "Eff" Then
Me.lvwData.Columns(k).Width = 37 * Ratio_X 'Eff
ElseIf lvwData.Columns(k).Text = "PF" Then
Me.lvwData.Columns(k).Width = 37 * Ratio_X 'PF
ElseIf lvwData.Columns(k).Text = "Cdtr ga." Then
Me.lvwData.Columns(k).Width = 50 * Ratio_X 'conductor gauge
ElseIf lvwData.Columns(k).Text = "Gnd ga." Then
Me.lvwData.Columns(k).Width = 50 * Ratio_X 'ground gauge
'normal sizing rules
Else : Me.lvwData.Columns(k).Width = 74 * Ratio_X 'Optional Columns
End If
Next
Else 'normal sizing rules
For k = 3 To 11
If lvwData.Columns(k).Text = "Cdtr ga." Then
Me.lvwData.Columns(k).Width = 50 * Ratio_X 'conductor gauge
ElseIf lvwData.Columns(k).Text = "Gnd ga." Then
Me.lvwData.Columns(k).Width = 50 * Ratio_X 'ground gauge
Else : Me.lvwData.Columns(k).Width = 74 * Ratio_X 'Optional Columns
End If
Next
End If
Next
lvwData.Scrollable = False
lvwData.EndUpdate()
'move and resize other controls
Me.pnlMain.Width = Me.Width - 8
Me.StatusBar1.Width = Me.pnlMain.Width
Me.StatusProgram.Width = Me.Width - 800 + 558
lblFileName.Location = New Point(191 + (Me.Width - 800) / 2, 41)
txtFileName.Location = New Point(251 + (Me.Width - 800) / 2, 34)
grpDeviceInfo.Location = New Point(5 + (Me.Width - 800) / 2, 54)
grpConductorInfo.Location = New Point(grpDeviceInfo.Location.X + 405, 25)
grpDistance.Location = New Point(grpDeviceInfo.Location.X + 588, 25)
grpNecWire.Location = New Point(grpDistance.Location.X, 92)
'refresh the container controls
grpDeviceInfo.Invalidate()
grpConductorInfo.Invalidate()
grpDistance.Invalidate()
grpNecWire.Invalidate()
pnlMain.Invalidate()
lvwData.Invalidate()
Me.ResumeLayout()
CheckGridLength() 'this is a special sub that checks the listview length and resizes the columns if it requires scroll bars.
Me.Refresh()
End Sub