如何判断动态加载的控件是否存在
1个回答
展开全部
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询