Public Structure ControlSizePosition
Public Name as String
Public Left As Single
Public Top As Single
Public Width As Single
Public Height As Single
Public FontSize As Single
End Structure
Private m_ControlSizePosition(150) As ControlSizePosition
Private m_FormWidth As Single
Private m_FormHeight As Single
'Save the form's and controls
Private Sub SaveSizes()
Dim i As Integer = 1
For Each Ctrl As Control In Me.Controls
If TypeOf Ctrl Is Panel Then
m_ControlSizePosition(i).Name = Ctrl.Name
m_ControlSizePosition(i).Left = Ctrl.Left
m_ControlSizePosition(i).Top = Ctrl.Top
m_ControlSizePosition(i).Width = Ctrl.Width
m_ControlSizePosition(i).Height = Ctrl.Height
On Error Resume Next
m_ControlSizePosition(i).FontSize = Ctrl.Font.Size
End If
For Each Ctl As Control In Ctrl.Controls
If TypeOf Ctl Is KB_Btn Then
m_ControlSizePosition(i).Name = Ctl.Name
m_ControlSizePosition(i).Left = Ctl.Left
m_ControlSizePosition(i).Top = Ctl.Top
m_ControlSizePosition(i).Width = Ctl.Width
m_ControlSizePosition(i).Height = Ctl.Height
On Error Resume Next
m_ControlSizePosition(i).FontSize = Ctl.Font.Size
End If
i += 1
Next Ctl
i += 1
Next Ctrl
' Save the form's size.
m_FormWidth = Me.Width
m_FormHeight = Me.Height
End Sub
Private Sub KeyBoard_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
SaveSizes()
End Sub
Private Sub KeyBoard_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
ResizeControls()
End Sub
'Arrange the controls for the new size.
Private Sub ResizeControls()
Dim i As Integer = 1
Dim Ctrl As Control
Dim x_scale As Single
Dim y_scale As Single
Dim sFont As Single
x_scale = Me.Width / m_FormWidth
y_scale = Me.Height / m_FormHeight
For Each Ctrl In Me.Controls
If TypeOf Ctrl Is Panel AndAlso Ctrl.Name = m_ControlSizePosition(i).Name Then
Ctrl.Left = x_scale * m_ControlSizePosition(i).Left
Ctrl.Top = y_scale * m_ControlSizePosition(i).Top
Ctrl.Width = x_scale * m_ControlSizePosition(i).Width
sFont = y_scale * m_ControlSizePosition(i).FontSize
With Ctrl
.Font = New Font(.Font.Name, sFont, .Font.Style, .Font.Unit)
End With
End If
For Each Ctl As Control In Ctrl.Controls
If TypeOf Ctl Is KB_Btn AndAlso Ctl.Name = m_ControlSizePosition(i).Name Then
Ctl.Left = x_scale * m_ControlSizePosition(i).Left
Ctl.Top = y_scale * m_ControlSizePosition(i).Top
Ctl.Width = x_scale * m_ControlSizePosition(i).Width
sFont = y_scale * m_ControlSizePosition(i).FontSize
With Ctl
.Font = New Font(.Font.Name, sFont, .Font.Style, .Font.Unit)
End With
End If
i += 1
Next Ctl
i += 1
Next Ctrl
End Sub