首页 > 解决方案 > 如何确定控件的 .Left 值?

问题描述

我正在 Microsoft Access 上的 VBA 中构建我的第一个用户界面。

我试图让 .Left 变量显示在下拉选择(库?)中。

唯一弹出的是LeftPadding,我很确定这不是我需要的。为什么我无法声明矩形的左侧位置?

图片

我应该使用另一种类型的变量来声明矩形的位置吗?

如果我做得正确,我的后续问题是关于嵌套 If 语句。我正在尝试计算新可见矩形的位置 + 它的尺寸是否超过了已经可见矩形的左侧位置,如果是,则将其放置在其他位置。

Dim ctl As Control
For Each ctl In [Forms]![frmBuilder]
    If Left(ctl.Name, 3) = "box" And Box1.Visible = True Then
        If ctl.Visible = True Then
            NextCaseNum = Int(Right(ctl.Name, (Len(ctl.Name)) - 3) + 1)
            NextCasePosition = (ctl.lef + ctl.Width) + 1440 / 60
            NextCaseName = "box" & NextCaseNum
        Else
            CurCaseLeft = ctl.Left
            CurCaseWidth = ctl.Width
            CurCaseHeight = ctl.Height
            With ctl
                .Top = UprightBottom - HInch
                .Left = NextCasePosition
                .Width = WInch
                .Height = HInch
                .Visible = True
            End With
            If CurCaseLeft + CurCaseWidth > Upright2.Left Then
                With Beam1
                    .Top = (((5.5 + 6) * 60) + Box1.Top) / 1440
                    .Left = Upright1.Left
                    .Height = (5.5 * 60) / 1440
                    .Width = ((4 * 60) / 1440) + Upright2.Left - Upright1.Left
                    .Visible = True
                End With
            End If

我认为问题出在 CurCaseLeft 和 CurCaseWidth 上,因为由于当前框的 ctl.Left 没有出现,我不知道如何在函数中定义它们。

我是否必须将嵌套的 If 语句分隔到另一个函数中并从当前函数中调用该函数?

标签: vbams-accesscontrolsrectangles

解决方案


尝试更明确:

Dim ctl As Control
Dim rct As Rectangle

For Each ctl In [Forms]![frmBuilder]
    If Left(ctl.Name, 3) = "box" And Box1.Visible = True Then
        If ctl.Visible = True Then
            Set rct = ctl
            NextCaseNum = Int(Right(rct.Name, (Len(rct.Name)) - 3) + 1)
            NextCasePosition = (rct.Left + rct.Width) + 1440 / 60

推荐阅读