Self Adjusting Userform Size

旧街凉风 提交于 2019-12-03 21:46:50

Here's one possible approach.

Private Sub UserForm_Activate()
    CheckSize
End Sub

Private Sub CommandButton1_Click()
    Me.lblTest.Visible = Not Me.lblTest.Visible
    CheckSize
End Sub

Private Sub CheckSize()
Dim h, w
Dim c As Control

    h = 0: w = 0
    For Each c In Me.Controls
        If c.Visible Then
            If c.Top + c.Height > h Then h = c.Top + c.Height
            If c.Left + c.Width > w Then w = c.Left + c.Width
        End If
    Next c

    If h > 0 And w > 0 Then
        With Me
            .Width = w + 40
            .Height = h + 40
        End With
    End If
End Sub

I found that the issue lied with display settings - I have my display set to 100% but others had theirs set to 150% so when they set it back to 100% they could view it correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!