1

我有一个自定义控件,我在 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)

我现在如何更新这些控件而不是清除它们并再次重新添加它们?

4

1 回答 1

3

尝试为您的控件提供唯一的名称:

Dim drive As New WindowsControlLibrary1.UserControl1()
drive.Name = "drive1"

那么您可以在面板的控件集合中按名称引用它们:

With DirectCast(Form1.FlowLayoutPanel1.Controls("drive1"), WindowsControlLibrary1.UserControl1)
  .BarValue = 50
End With
于 2012-05-24T20:32:01.833 回答