代码之家  ›  专栏  ›  技术社区  ›  Aakash

如何在MS ACCESS 2007中调整并排控件的大小

  •  0
  • Aakash  · 技术社区  · 11 年前

    我有一个表单,其中有各种字段,例如,两个文本框并排。 这两个文本框具有锚点属性left,top和其他right,top。

    现在,当我调整表单大小时,控件向左对齐,另一个文本框向右对齐。 但当屏幕最大化时,这两个文本框之间会留下空白。

    因此,我将两个文本框的锚属性设置为两个,两个控件重叠。

    PS:在MS ACCESS 2007上工作。 上面的锚定属性为“水平”、“垂直”

    EDIT:在“正常”窗口中

    __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ 最小-最大关闭 _

    |名字TEXTBOX姓氏TEXTBOX|

    | _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ |

    当最大化到整个屏幕时

    __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ _ 最小-最大关闭 _

    |名字文本框。。。。。。。。。。。。。。。。。。。。。。。。。。。。。姓氏TEXTBOX|

    | _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ |

    我需要这样的方式

    __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ _ 最小-最大关闭 _

    |F i r s t_N a m e t e X t B O X。。。。。。。。L a s t_N a m e t e X t B O X公司|

    | _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ |

    我试图通过这样做来解释,因为我不被允许上传图像,抱歉。。。。

    1 回复  |  直到 11 年前
        1
  •  0
  •   Wayne G. Dunn    11 年前

    将以下代码粘贴到表单中,更改字段名称,然后查看结果。当您增加表单宽度时,这两个字段将“增长”,但保持其锚点。注意:我在3/3更新了字段标签。

    Option Compare Database
    Option Explicit
    
    Dim fviInsideWidth  As Integer
    Dim fviSaveInsideWidth  As Integer
    Dim fviFormWidth    As Integer
    Dim fviFldWidth     As Integer
    Dim fviFieldGap     As Integer
    Dim fviRemainder    As Integer
    Dim fviLblWidth     As Integer
    Dim fviRLblToTxt    As Integer
    Dim fvstrLLabel     As String
    Dim fvstrRLabel     As String
    
    Private Sub Form_Open(Cancel As Integer)
        fviSaveInsideWidth = Me.InsideWidth
        fviInsideWidth = Me.InsideWidth
        fviFormWidth = Me.Width
        fviFldWidth = Me.fldLeft.Width + Me.fldRight.Width
        fviRemainder = fviInsideWidth - fviFldWidth
        fviFieldGap = Me.fldRight.Left - (Me.fldLeft.Left + Me.fldLeft.Width)
        fvstrLLabel = Me.fldLeft.Controls.Item(0).Name
        fvstrRLabel = Me.fldRight.Controls.Item(0).Name
        fviLblWidth = Me.Controls(fvstrRLabel).Width
        fviRLblToTxt = Me.fldRight.Left - Me.Controls(fvstrRLabel).Left
        'Debug.Print "Open - InsideWidth = " & fviInsideWidth & "  Fields: " & fviFldWidth & "  Remainder: " & fviRemainder
        'Debug.Print "Open - Form Width  = " & Me.Width & vbTab & "Diff = " & fviInsideWidth - fviFormWidth
    End Sub
    
    Private Sub Form_Close()
        Me.fldLeft.Width = fviFldWidth
        Me.fldRight.Width = fviFldWidth
        Me.InsideWidth = fviSaveInsideWidth
    End Sub
    
    
    Private Sub Form_Resize()
        Dim ifldWidth   As Integer
        Dim ifrmWidth   As Integer
        fviInsideWidth = Me.InsideWidth
        ifrmWidth = fviInsideWidth - 1110
        Me.Width = ifrmWidth
        ifldWidth = Int((fviInsideWidth - fviRemainder) / 2)
        Me.fldLeft.Width = ifldWidth
        Me.fldRight.Left = Me.fldLeft.Left + Me.fldLeft.Width + fviFieldGap
        Me.Controls(fvstrRLabel).Left = Me.fldRight.Left - fviRLblToTxt
        Me.fldRight.Width = ifldWidth
        'Debug.Print "Resize - InsideWidth = " & fviInsideWidth & vbTab & "Form Width = " & Me.Width & " Flds: " & ifldWidth & " Right=" & Me.fldLeft.Left + Me.fldLeft.Width + fviFieldGap
        'Debug.Print "Resize Form: " & Me.Width & " Flds: " & ifldWidth
        Me.Repaint
    End Sub