我正在为Windows平板电脑编写一个全屏程序,无论旋转如何,都需要调整所有控件的大小以适应屏幕。
现在我正在使用以下内容:
Private Sub CreateOrder_Resize(sender As Object, e As EventArgs) Handles MyBase.Resize
Dim widthMultiplier As Decimal = (Me.Width * 0.99) / itemsPanel.Width 'this panel is 99% as tall as the form initially, and 80% as tall
Dim heightMultiplier As Decimal = (Me.Height * 0.8) / itemsPanel.Height
resizeEverything(Me.Controls, widthMultiplier, heightMultiplier)
End Sub
Private Sub resizeEverything(ByRef container As Object, ByVal widthMultiplier As Decimal, ByVal heightMultiplier As Decimal)
For Each screenItem In container
screenItem.location = New Point(screenItem.location.x * widthMultiplier, screenItem.location.y * heightMultiplier)
screenItem.size = New Size(screenItem.width * widthMultiplier, screenItem.height * heightMultiplier)
checkIfFont(screenItem, widthMultiplier)
If screenItem.GetType() = (New Panel).GetType Then
resizeEverything(screenItem.controls, widthMultiplier, heightMultiplier)
End If
Next
End Sub
Private Sub checkIfFont(ByRef viewObject As Object, ByVal multiplier As Decimal)
Dim fontCarriers() As Object = {New RichTextBox, New Label, New TextBox, New ListBox, New DateTimePicker, New ComboBox}
For Each controlType In fontCarriers
If viewObject.GetType = controlType.GetType Then
controlType = viewObject
Dim myFont As Font = controlType.font
Dim newFont As Font = New Font(myFont.Name, myFont.Size * multiplier, myFont.Style)
viewObject.font = newFont
Exit For
End If
Next
End Sub
事实证明,对于我必须使用的一些平板电脑而言,这种资源非常耗费资源。
我没有使用自动缩放,因为当平板电脑在纵向模式下使用时,表格需要“挤压”,据我所知,自动缩放保持宽高比。
那么,如果不磨练并调整每个控件的大小,我怎么能这样做呢?