|
3#
發(fā)表于 2005-3-31 06:47:00
|
只看該作者
回復:(goodidea)另類控件自適應窗體
在Resize事件中通過遍歷窗體控件進行判斷和設置,變量 i 記錄第幾行,, j 記錄當前變量的右邊位置。
Private Sub Form_Load()
Dim ctl As Control
For Each ctl In Me.Controls
If Not TypeOf ctl Is Label And ctl.Name <> "BZ" Then
ctl.Tag = ctl.Width
End If
Next
End Sub
Private Sub Form_Resize()
Echo False
Dim i As Integer, j As Integer, ctl As Control, ctlLast As Control
Me.Width = Me.InsideWidth - 50
Me.BZ.Left = Me.InsideWidth - Me.BZ.Width - 100
Me.BZ_標簽.Left = Me.BZ.Left
Me.BZ.Height = Me.InsideHeight - 500
For Each ctl In Me.Controls
If Not TypeOf ctl Is Label And ctl.Name <> "BZ" Then
If j <> 0 And j + 50 + Controls(ctl.Name & "_標簽").Width + Val(ctl.Tag) > Me.InsideWidth - Me.BZ.Width - 100 Then
j = 0
Me.主體.Height = Me.主體.Height + 1000
i = i + 1
If Not ctlLast Is Nothing Then ctlLast.Width = Me.InsideWidth - Me.BZ.Width - 100 - ctlLast.Left - 100
End If
Controls(ctl.Name & "_標簽").Top = i * 500 + 100
Controls(ctl.Name & "_標簽").Left = j + 50
ctl.Top = i * 500 + 100
ctl.Left = Controls(ctl.Name & "_標簽").Left + Controls(ctl.Name & "_標簽").Width
If 50 + Controls(ctl.Name & "_標簽").Width + Val(ctl.Tag) > Me.InsideWidth - Me.BZ.Width - 100 Then
ctl.Width = Me.InsideWidth - Me.BZ.Width - 100 - ctl.Left - 100
Else
ctl.Width = Val(ctl.Tag)
End If
Set ctlLast = ctl
j = ctl.Left + ctl.Width
End If
Next
Me.主體.Height = Me.InsideHeight
Echo True
End Sub
|
本帖子中包含更多資源
您需要 登錄 才可以下載或查看,沒有帳號?注冊
x
|