如何判断动态加载的控件是否存在
发布网友
发布时间:2022-04-24 23:10
我来回答
共1个回答
热心网友
时间:2022-04-25 00:39
Dim LB(7) As Label 'label数组
Dim y As Int16 = 0
Dim fr As New Form3 '将在该窗口添加控件
fr.Show()
For i As Integer = 0 To LB.GetLength(0) - 1
'这段循环在fr上添加label控件,从上至下依次显示0~7
LB(i) = New Label
With LB(i)
.Text = i
.Left = 10
y += 25
.Top = y
End With
fr.Controls.Add(LB(i))
Next
y = 0
For i As Integer = 0 To LB.GetLength(0) - 1
'这段循环在fr上反转label控件的值,并扩大两个控件间的垂直距离, 从上至下依次显示7~0
''注释部分可不要
'If fr.Contains(LB(i)) Then
' fr.Controls.Remove(LB(i))
'End If
With LB(i)
.Text = LB.GetLength(0) - 1 - i
.Left = 10
y += 40
.Top = y
End With
'fr.Controls.Add(LB(i)) '这里也可不要
Next