2012-05-24 56 views
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) 

如何我現在可以更新這些控件,而不是清除它們並重新加入他們呢?

回答

3

嘗試給您的控件的唯一名稱:

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

那麼你可以參考它們在面板的控件集合中的名字:

With DirectCast(Form1.FlowLayoutPanel1.Controls("drive1"), WindowsControlLibrary1.UserControl1) 
    .BarValue = 50 
End With 
相關問題