|
回复:(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
|