修屏幕的方法

How to fix the screen

我在 VisualBasic 6 中开始一个项目,我需要通过一个按钮在其中添加更多的 TextBox / CheckBox / ComboBox。问题是当你添加它们时,屏幕被解包。我附上图片以便更好地压缩:

这是创建的表单(按下按钮后应显示框架内的内容。(索引为 0,可见为 false)):

当我启动应用程序时,它看起来像这样:

当我按下按钮时,会发生这种情况:

我的想法是它看起来像第一张图片,我在其中展示了创建的表单。这是我使用的所有代码:

Dim index As Integer

Private Sub btnAdd_Click ()
index = index + 1 'we increase the index

Load UserControl1 (index)'here is the error
UserControl1 (index) .Visible = True
UserControl1 (index) .Top = UserControl1 (index - 1) .Top + UserControl1 (index - 1) .Hight + 20 'this not work to me. Error: Sub or Function not defined

'frmAdd
Load frmAdd (index) 'we create the control
frmAdd (index) .Visible = True 'we make it visible
frmAdd (index) .Top = frmAdd (index - 1) .Top + frmAdd (index - 1) .Height + 20
'frmAdd (index) .Top = frmAdd (index - 1) .Top + frmAdd (index) .Height move the control

'cmbAddType
Load cmbAddType (index)
Set cmbAddType (index) .Container = frmAdd (index)
cmbAddType (index) .Visible = True
cmbAddType (index) .Top = cmbAddTipo (index - 1) .Top
'cmbAddType (index) .Top = cmbAddTipo (index - 1) .Top + cmbAddType (index) .Height

'txtAddPrefix
Load txtAddPrefix (index)
Set txtAddPrefix (index) .Container = frmAdd (index)
txtAddPrefix (index) .Visible = True
txtAddPrefix (index) .Top = txtAddPrefix (index - 1) .Top

'txtAddNumber
Load txtAddNumber (index)
Set txtAddNumber (index) .Container = frmAdd (index)
txtAddNumber (index) .Visible = True
txtAddNumber (index) .Top = txtAddNumber (index - 1) .Top

'checkAddPrincipal
Load checkAddPrincipal (index)
Set checkAddPrincipal (index) .Container = frmAdd (index)
checkAddPrincipal (index) .Visible = True
checkAddPrincipal (index) .Top = checkAddPrincipal (index - 1) .Top

'cmbAdd Link
Load cmbAdd Link (index)
Set cmbAdd Link (index) .Container = frmAdd (index)
cmbAdd Link (index) .Visible = True
cmbAddLink (index) .Top = cmbAddLink (index - 1) .Top

End Sub

将图像添加到我的用户控件:

不是 Visible 属性 在用户控件中:

用户控件中没有 Index 属性:

您至少可以通过两种方式解决问题:修正您的方法或采用 Etienne 的方法。要修复您的方法,请尝试以下代码。主要修复是为子控件设置 Container 属性 并调整 Top 计算:

Private Sub btnAdd_Click()
   index = index + 1

   Load Frame1(index)
   Frame1(index).Visible = True
   Frame1(index).Top = Frame1(index - 1).Top + Frame1(index - 1).Height + 20

   Load Command1(index)
   Set Command1(index).Container = Frame1(index)
   Command1(index).Visible = True
   Command1(index).Top = Command1(index - 1).Top

   'etc, etc, etc
End Sub

更简单的方法是使用 UserControl。使用这种方法,您的代码变为:

Private Sub btnAdd_Click()
   index = index + 1

   Load UserControl11(index)
   UserControl11(index).Visible = True
   UserControl11(index).Top = UserControl11(index - 1).Top + UserControl11(index - 1).Height + 20
End Sub