如何确定控件的.Left值?

问题描述 投票:1回答:1

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

我正在尝试使.Left变量显示在下拉选择中(库?)。

唯一弹出的是LeftPadding,我敢肯定这不是我所需要的。为什么我不能声明矩形的左位置?

Image

还有其他类型的变量我应该用来声明矩形的位置吗?

如果我正确执行,我的跟进问题是关于嵌套的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语句分离到另一个函数中,并从当前函数中调用该函数?

vba ms-access controls rectangles
1个回答
0
投票

尝试更明确:

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
© www.soinside.com 2019 - 2024. All rights reserved.