0

基本的に私が持っているものは次のとおりです。

Public checkprogresstime_p1 As String = ""
Public checkprogresstime_p2 As String = ""

'P1 Progress bar updater
checkprogresstime_p1 = (time_total.Text - time_p1_hour.Value)
If checkprogresstime_p1 >= 60 Then
    checkprogresstime_p1 = 60
    time_p1_progress.ForeColor = Color.LimeGreen
ElseIf checkprogresstime_p1 <= 0 Then
    checkprogresstime_p1 = 1
End If
If time_p1_progress.Value < 60 Then
    time_p1_progress.ForeColor = Color.Red
End If
time_p1_progress.Value = checkprogresstime_p1

基本的に必要なものは次のとおりです。

Dim cnt As Integer = 1     

Do
    'P1 Progress bar updater
    checkprogresstime_p(cnt) = (time_total.Text - time_p(cnt)_hour.Value)
    If checkprogresstime_p(cnt) >= 60 Then
        checkprogresstime_p(cnt) = 60
        time_p(cnt)_progress.ForeColor = Color.LimeGreen
    ElseIf checkprogresstime_p(cnt) <= 0 Then
        checkprogresstime_p(cnt) = 1
    End If
    If time_p(cnt)_progress.Value < 60 Then
        time_p(cnt)_progress.ForeColor = Color.Red
    End If
    time_p(cnt)_progress.Value = checkprogresstime_p(cnt)
Loop While cnt <= 25

私はそれを行う方法がわかりません...ループして+1を25回追加する必要があります。私は基本的に現時点で25回書き出しています...

4

2 に答える 2

1

これはFor/Loopあなたの現在のリクエストです。このcntタイプの では、変数はそれ自体をインクリメントしますLoop

For cnt As Integer = 1 To 25
 'P1 Progress bar updater
 checkprogresstime_p(cnt) = (time_total.Text - time_p(cnt)_hour.Value)
 If checkprogresstime_p(cnt) >= 60 Then
    checkprogresstime_p(cnt) = 60
    time_p(cnt)_progress.ForeColor = Color.LimeGreen
 ElseIf checkprogresstime_p(cnt) <= 0 Then
    checkprogresstime_p(cnt) = 1
 End If
 If time_p(cnt)_progress.Value < 60 Then
    time_p(cnt)_progress.ForeColor = Color.Red
 End If
 time_p(cnt)_progress.Value = checkprogresstime_p(cnt)
Next
于 2013-09-14T02:16:56.267 に答える
0

あなたがやりたいことは、フォームに25個のプログレスバーがあり、それぞれに名前が付けられていることと関係があると思います.プログレスバーの番号はtime_p#_progressどこですか. #そうは言っても、コードを 25 回コピーして貼り付けることなく、進行状況バーを更新する方法は 2 つあります...

1.Me.Controls進行状況バーへの参照を取得するために使用します

For j = 1 To 25
    Dim pbar As ProgressBar = Me.Controls("time_p" & j & "_progress")
    Dim ph As NumericUpDown = Me.Controls("time_p" & j & "_hour")
    Dim checkprogresstime As Long = (time_total.Text - ph.Value)
    If checkprogresstime >= 60 Then
        checkprogresstime = 60
        pbar.ForeColor = Color.LimeGreen
    ElseIf checkprogresstime <= 0 Then
        checkprogresstime = 1
    End If
    If time_p1_progress.Value < 60 Then
        pbar.Value = checkprogresstime
    End If
    pbar.Value = checkprogresstime
    Application.DoEvents()
Next

注: コントロールの種類を教えてくれませんでしtime_p1_hourた。NumericUpDownダウンコントロールだったと思います。そうでない場合は、そのタイプのコントロールに置き換える必要がありtime_p1_hourます。

2. コントロールをコントロール配列として動的に作成する

Form1_Load メソッド (MyBase.Load) でプログレス バーを初期化します。

Private pbars(24) As ProgressBar

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    For i = LBound(pbars) To UBound(pbars)
        pbars(i) = New ProgressBar()
        pbars(i).Parent = Me
        pbars(i).Top = i * pbars(i).Height
        pbars(i).Left = 0
        pbars(i).Visible = True
    Next
End Sub

コードをループの中に入れます

For cnt = 0 To 24
    checkprogresstime_p(cnt) = (time_total.Text - time_hour(cnt).Value)
    If checkprogresstime_p(cnt) >= 60 Then
        checkprogresstime_p(cnt) = 60
        time_p_progress(cnt).ForeColor = Color.LimeGreen
    ElseIf checkprogresstime_p(cnt) <= 0 Then
        checkprogresstime_p(cnt) = 1
    End If
    If time_p_progress(cnt).Value < 60 Then
        time_p_progress(cnt).ForeColor = Color.Red
    End If
    time_p_progress(cnt).Value = checkprogresstime_p(cnt)
Next
于 2013-09-14T02:35:59.220 に答える