如何找到另一个控件左侧是否存在控件。 例如,我们通常将标签放在左侧的文本框中。在我,我有50多个 控制,我想扩大它们。逐个扩大是耗时的。我怎样才能找到一个控件及其宽度,放在另一个控件上。任何人都可以建议在代码中实现这一目标。我正在使用vb6。这是我的代码,这不起作用
For Each crl In Me.Controls
'crl.Width = crl.Width + 750
If crl.Left < 150 Then
crl.Left = crl.Left + 2000
Else
crl.Left = (crl.Width / 2) + crl.Left + 1000
End If
crl.Top = crl.Top + 500
'crl.Height = crl.Height + 100
'crl.Width = crl.Width + 750
Next
答案 0 :(得分:1)
控件布局中是否有一些逻辑结构?
如果是这种情况,那么您可以使用Form_Resize()事件来定位(并调整大小)控件
例如,一个包含10个标签和10个文本框的表单,布局为5 x 2行x列
'1 form with:
'1 textbox : name=Text1 Index=0
'1 label : name=Label1 Index=0
Option Explicit
Private Sub Form_Load()
Dim intIndex As Integer
'load extra labels and textboxes
For intIndex = 1 To 9
Load Label1(intIndex)
Label1(intIndex).Caption = "Label" & CStr(intIndex + 1)
Label1(intIndex).Visible = True
Load Text1(intIndex)
Text1(intIndex).Text = "Text" & CStr(intIndex + 1)
Text1(intIndex).Visible = True
Next intIndex
End Sub
Private Sub Form_Resize()
Dim intIndex As Integer
Dim intRow As Integer, intCol As Integer
Dim sngWidth As Single, sngHeight As Single
'calculate width and height of each control
sngWidth = ScaleWidth / 4
sngHeight = ScaleHeight / 5
'loop through all controls and position and resize them
For intIndex = 0 To 9
intCol = intIndex \ 5
intRow = intIndex Mod 5
Label1(intIndex).Move 2 * intCol * sngWidth, intRow * sngHeight, sngWidth, sngHeight
Text1(intIndex).Move (2 * intCol + 1) * sngWidth, intRow * sngHeight, sngWidth, sngHeight
Next intIndex
End Sub