2014-12-06 21 views
-2

首先我的代码:如何更新每个循环中每个代码创建的进度条/标签?

Sub festplatte() 
    Dim allDrives() As DriveInfo = DriveInfo.GetDrives() 
    Dim d As DriveInfo 
    Dim I As Integer 
    For Each d In allDrives 
     If d.IsReady = True Then 
      Try 
       ' Intelize controls 
       Dim progressbar As ProgressBar = New ProgressBar 
       Dim pbgroup As GroupBox = New GroupBox 
       Dim info As Label = New Label 
       Dim type As Label = New Label 
       Dim format As Label = New Label 
       Dim Space As Double = d.TotalFreeSpace/d.TotalSize 
       ' Add to tab 
       Me.Tab_M.Controls.Add(progressbar) 
       Me.Tab_M.Controls.Add(pbgroup) 
       Me.Tab_M.Controls.Add(info) 
       Me.Tab_M.Controls.Add(type) 
       Me.Tab_M.Controls.Add(format) 
       ' Add to group 
       pbgroup.Controls.Add(progressbar) 
       pbgroup.Controls.Add(info) 
       pbgroup.Controls.Add(type) 
       pbgroup.Controls.Add(format) 
       pbgroup.Text = d.Name & " | Name : " & CheckName(d.VolumeLabel.ToString()) 
       pbgroup.Size = New System.Drawing.Size(600, 65) 
       pbgroup.Location = New System.Drawing.Point(8, I * 70 + 40) 
       ' format 
       format.AutoSize = True 
       format.Name = "format" & I 
       format.Location = New System.Drawing.Point(435, 36) 
       format.Text = "Format : " & d.DriveFormat 
       ' Typ 
       type.AutoSize = True 
       type.Name = "type" & I 
       type.Location = New System.Drawing.Point(435, 16) 
       type.Text = "Art : " & GetDriverFormat(d) 
       ' info 
       info.Name = "info" & I 
       info.Location = New System.Drawing.Point(6, 16) 
       info.AutoSize = True 
       ' Info Text :: 1000 MB Grenze 
       If d.TotalFreeSpace > Math.Pow(1024, 3) Then 
        info.Text = "Benutzter Speicher beträgt : " & Math.Round((d.TotalSize - d.TotalFreeSpace)/btogb, 2) & " GB von " & Math.Round((d.TotalSize)/btogb, 2) & " GB (" & Math.Round(100 - Space * 100, 2) & " %)" 
       Else 
        info.Text = "Benutzter Speicher beträgt : " & Math.Round((d.TotalSize - d.TotalFreeSpace)/btomb, 2) & " MB von " & Math.Round((d.TotalSize)/btomb, 2) & " MB (" & Math.Round(100 - Space * 100, 2) & " %)" 
       End If 
       'Progressbar 
       progressbar.Size = New System.Drawing.Size(425, 23) 
       progressbar.Location = New System.Drawing.Point(6, 32) 
       progressbar.Name = "Memory" & I 
       progressbar.Value = 100 - Space * 100 

      Catch ex As Exception 
       MsgBox(ex.ToString()) 
      End Try 
      I += 1 
     End If 
    Next 
End Sub 

代码中并产生与它每一个进度条和3个标签,在这里我想编辑东西组框。

如何编辑例如标签的文本?我怎样才能从表单中添加/删除生成的元素?我试图刷新,但它不工作

The Form

+0

你想在标签上写什么?磁盘名称或%等可能会更新您的问题,并提供更多关于您想要执行的操作的信息。 – Creator 2014-12-06 23:35:00

+0

并请发布运行此代码所需的代码“有你的贴子以外的东西”CheckName和GetDriverFormat等 – Creator 2014-12-07 03:24:16

+0

对不起:标签应显示驱动器的已用大小和使用的驱动器的百分比。功能:Checkname检查卷标是否为空或什么(“” - > Nothing)GetDriverFormat是一个带有select case的函数,它只是转换驱动器的格式(例如Fixed - > into german:Festplatte) – NoSenseSenpai 2014-12-07 19:13:33

回答

2

这是一件很快我想:

Dim LabelList As New List(Of Integer) 

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click 
    Dim LBL As New Label 
    LBL.Location = New Point(6, 23) 
    LBL.AutoSize = True 

    Me.Controls.Add(LBL) 
    LabelList.Add(Me.Controls.Count - 1) 
End Sub 

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click 
    Me.Controls(LabelList(0)).Text = "HELLO WORLD!" 
End Sub 

这将一个标签添加到窗体,然后添加它的控制指标LabelList。 LabelList(0)将获得第一个添加标签的索引。

+0

请[接受答案](http://meta.stackexchange.com/a/5235/155831)是否有助于解决问题。 – 2016-12-14 16:42:47

相关问题