我有一个自定义控件,我在flowlayoutpanel中添加了一些:
Dim drive As New WindowsControlLibrary1.UserControl1()
drive.FileSystemlable = reader.GetString(2)
drive.AbalableSpaceLable = Convert.ToInt32(reader.GetString(4) / 1024)
drive.TotalSpaceLable = Convert.ToInt32(reader.GetString(5) / 1024)
drive.SetVolumeLable = reader.GetString(3)
Dim usedspace As Integer = Convert.ToInt32(reader.GetString(5)) - Convert.ToInt32(reader.GetString(4))
drive.BarValue = usedspace / 1024
Form1.FlowLayoutPanel1.Controls.Add(drive)
我现在如何更新这些控件而不是清除它们并重新添加它们?
答案 0 :(得分:3)
尝试为控件提供唯一的名称:
Dim drive As New WindowsControlLibrary1.UserControl1()
drive.Name = "drive1"
然后您可以通过名称在面板的控件集合中引用它们:
With DirectCast(Form1.FlowLayoutPanel1.Controls("drive1"), WindowsControlLibrary1.UserControl1)
.BarValue = 50
End With