gpt4 book ai didi

VB.NET:代码不检查面板中是否存在控件

转载 作者:行者123 更新时间:2023-12-02 17:46:03 30 4
gpt4 key购买 nike

我的代码:

Rs.Open("Select * From Notifications",Con)
If Not Rs.EOF Then
For i=0 to Rs.RecordCount -1
Dim Label As New Label
With Label
.Name = String.Format("Label_{0}",Rs("Id").Value.ToString)
.Text = Rs("Notification").Value.ToString
End With
If Not Panel.Controls.Contains(Label) Then
Panel.Control.Add(Label)
End If
Rs.MoveNext()
Next
End If

但这总是给面板添加控制,下面的代码行没有正确执行:(如果不是 Panel.Controls.Contains(Label)则)

此代码适用于计时器。

最佳答案

Function CntrlExistsIn(ctrlName as String, parent as Control) as Boolean
Dim bResult as Boolean = False

For Each elem as Control In parent.Controls
If elem.Name = ctrlName Then
bResult = True
Exit For
End If
Next

Return bResult
End Function

以上函数是检查Panel中是否存在control(label)

关于VB.NET:代码不检查面板中是否存在控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14476974/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com