原出處
1.使用「相對位置」和「相對大小」來決定每個控制項的顯現參數(.Width、 .Height、.top、.Left)。
2.程式碼:
Private Type 物件資訊
名稱 As String
位置x As Single
位置y As Single
寬度 As Single
高度 As Single
字型大小 As Single
End Type
Dim myobj() As 物件資訊
Private Sub Form_Load()
Me.AutoRedraw = True
On Error Resume Next
n = 0
For Each i In Controls
ReDim Preserve myobj(n)
With myobj(n)
.名稱 = i.Name
.位置x = i.Left / Me.ScaleWidth
.位置y = i.Top / Me.ScaleHeight
.高度 = i.Height / Me.ScaleHeight
.寬度 = i.Width / Me.ScaleWidth
.字型大小 = i.Font.Size / Me.ScaleHeight
End With
n = n + 1
Next
End Sub
Private Sub Form_Resize()
On Error Resume Next
For Each i In Controls
For j = 0 To UBound(myobj)
If i.Name = myobj(j).名稱 Then
i.Top = myobj(j).位置y * Me.ScaleHeight
i.Left = myobj(j).位置x * Me.ScaleWidth
i.Width = myobj(j).寬度 * Me.ScaleWidth
i.Height = myobj(j).高度 * Me.ScaleHeight
i.Font.Size = myobj(j).字型大小 * Me.ScaleHeight
End If
Next
Next
End Sub
3.效果(各控制項可依開啟的視窗大小自動調整):
http://db3.tspes.tpc.edu.tw/demo/img/961126form0.jpg
沒有留言:
張貼留言