你如何在Access表单中移动控件?

huangapple go评论66阅读模式
英文:

How can you move controls around an Access form?

问题

我正在处理一个Access数据库,并需要移动表单上的文本框和标签。我试图使用.Move函数来移动表单上的控件,但似乎它不正常工作,因为它只会将所有指定的元素移动到表单的左上角,无论指定了什么。

这是我的代码:

Private Sub Form_Activate()
    Dim gObj As Control
    Dim lObj As Control
    Dim llObj As Control
    Dim lllObj As Control
    Dim llllObj As Control
    Dim aObj As Control
    Dim aaObj As Control
    Dim aaaObj As Control
    Dim condit As String
    Dim x1 As Variant
    Dim x2 As Variant
    Dim y1 As Variant
    Dim y2 As Variant
    
    x1 = 0.0417
    x2 = 0.0417
    t1 = 0.5417
    t2 = 0.7917
    For i = 0 To 22
        Set gObj = Me.Controls("G" & i)
        If gObj.Value Then
            condit = gObj.Value
        Else
            condit = ""
        End If
        If condit = "" Or condit = "0" Then
            Set lObj = Me.Controls("L" & i)
            Set llObj = Me.Controls("LL" & i)
            Set lllObj = Me.Controls("LLL" & i)
            Set llllObj = Me.Controls("LLLL" & i)
            
            Set aObj = Me.Controls("A" & i)
            Set aaObj = Me.Controls("AA" & i)
            Set aaaObj = Me.Controls("AAA" & i)
            
            gObj.Visible = False
            lObj.Visible = False
            llObj.Visible = False
            lllObj.Visible = False
            llllObj.Visible = False
            
            aObj.Visible = False
            aaObj.Visible = False
            aaaObj.Visible = False
        Else
            Set lObj = Me.Controls("L" & i)
            Set llObj = Me.Controls("LL" & i)
            Set lllObj = Me.Controls("LLL" & i)
            Set llllObj = Me.Controls("LLLL" & i)

            Set aObj = Me.Controls("A" & i)
            Set aaObj = Me.Controls("AA" & i)
            Set aaaObj = Me.Controls("AAA" & i)

            'lObj.Move Left:=x1, Top:=t1
            'lObj.Move Top:=t1

            'gObj.Move Left:=x2, Top:=t2
            'gObj.Move Top:=t2
            lObj.Move Left:=x1, Top:=t1
            gObj.Move Left:=x2, Top:=t2
            x1 = x1 + 0.7916
            x2 = x2 + 0.7916
        End If
    Next
End Sub

我是否错误使用了.Move函数?它似乎与Microsoft文档中提供的一致。

我尝试了多种不同的语法组合来使用.Move函数,但到目前为止都没有成功。我能够在y轴上移动元素,但不能在x轴上移动。

英文:

I am working on an Access database and need to move text boxes and labels around a form. I am trying to use the .Move function to move the controls around on the form but it doesn't seem to work properly as all it will do is move all of the specified elements to the top left corner of the form regardless of what is specified.
This is my code,

Private Sub Form_Activate()
    Dim gObj As Control
    Dim lObj As Control
    Dim llObj As Control
    Dim lllObj As Control
    Dim llllObj As Control
    Dim aObj As Control
    Dim aaObj As Control
    Dim aaaObj As Control
    Dim condit As String
    Dim x1 As Variant
    Dim x2 As Variant
    Dim y1 As Variant
    Dim y2 As Variant
    
    x1 = 0.0417
    x2 = 0.0417
    t1 = 0.5417
    t2 = 0.7917
    For i = 0 To 22
        Set gObj = Me.Controls("G" & i)
        If gObj.Value Then
            condit = gObj.Value
        Else
            condit = ""
        End If
        If condit = "" Or condit = "0" Then
            Set lObj = Me.Controls("L" & i)
            Set llObj = Me.Controls("LL" & i)
            Set lllObj = Me.Controls("LLL" & i)
            Set llllObj = Me.Controls("LLLL" & i)
            
            Set aObj = Me.Controls("A" & i)
            Set aaObj = Me.Controls("AA" & i)
            Set aaaObj = Me.Controls("AAA" & i)
            
            gObj.Visible = False
            lObj.Visible = False
            llObj.Visible = False
            lllObj.Visible = False
            llllObj.Visible = False
            
            aObj.Visible = False
            aaObj.Visible = False
            aaaObj.Visible = False
            Else
                Set lObj = Me.Controls("L" & i)
                Set llObj = Me.Controls("LL" & i)
                Set lllObj = Me.Controls("LLL" & i)
                Set llllObj = Me.Controls("LLLL" & i)

                Set aObj = Me.Controls("A" & i)
                Set aaObj = Me.Controls("AA" & i)
                Set aaaObj = Me.Controls("AAA" & i)

                'lObj.Move Left:=x1, Top:=t1
                'lObj.Move Top:=t1

                'gObj.Move Left:=x2, Top:=t2
                'gObj.Move Top:=t2
                lObj.Move lObj.Left = x1, lObj.Top = t1
                gObj.Move gObj.Left = x2, gObj.Top = t2
                x1 = x1 + 0.7916
                x2 = x2 + 0.7916
            End If
        Next
End Sub

Am I using the .Move function wrong it seems to be in line with the documentation provided on the Microsoft Documentation.

I have tried multiple different syntax combinations for the .move function but none have worked so far. I am able to move elements on the y-axis but no the x-axis.

答案1

得分: 2

.Move参数以为单位。

> 每英寸约为1440个点,每厘米约为567个点。

因此,如果使用小于1的值,它们都会聚集在左上角,这并不奇怪。
尝试:

Const TPC = 567  ' 每厘米的点数
x1 = 0.0417 * TPC
t1 = 0.5417 * TPC

lObj.Move 左:=x1, 顶:=t1
英文:

.Move parameters are in Twips.

> There are approximately 1440 twips to a logical inch or 567 twips to a logical centimeter

So it's not surprising they all get clustered in the top left if you use values < 1.
Try:

Const TPC = 567  &#39; Twips per centimeter
x1 = 0.0417 * TPC
t1 = 0.5417 * TPC

lObj.Move Left:=x1, Top:=t1

huangapple
  • 本文由 发表于 2023年6月8日 04:33:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76426934.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定