2013-08-17 37 views
1

我有12 controls,我想在for循環中更改它們的值。我嘗試了很多方法,但是我無法解決這個問題。如何更改for循環中的屬性

這裏是我的代碼:

Dim serviceNames() As String = {"Security Manager Remote Recorder", _ 
    "Security Manager Filter", "Security Manager Prob", _ 
    "Security Manager Intelligence", "Security Manager Maintenance", _ 
    "Security Manager Action", "Security Manager Agent Check", _ 
    "Security Manager Control", "Security Manager Deploy Copy", _ 
    "Security Manager Monitor", "Security Manager Reloader", _ 
    "Security Manager Schedule"} 
Dim swButtons() = {sw0.Value, sw1.Value, sw2.Value, sw3.Value, sw4.Value, _ 
    sw5.Value, sw6.Value, sw7.Value, sw8.Value, sw9.Value, sw10.Value, sw11.Value} 

For q As Integer = 0 To serviceNames.Count - 1 
    Dim regService = My.Computer.Registry.GetValue(_ 
     "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\" + _ 
     serviceNames(q) + "", "Start", "") 

    If regService = 2 Then 
     swButtons(q) = True 
    End If 

    If regService = 4 Then 
     MetroTabItem5.Text = "bu 4" 
    End If 
Next 
+0

明確解釋你的問題嗎? –

+0

好吧,所以我有12個按鈕放置窗體窗體,我想創建循環,然後啓動1到12按鈕啓用屬性在for循環中爲false。對不起,我的英語不夠清楚地解釋這個問題。謝謝。 – brooqs

+0

什麼類型是'swButtons()'?他們是按鈕嗎?什麼是'sw0.Value','sw1.Value'等?換句話說,如何定義'sw0.Value'和其他? – Tim

回答

-1

如果我理解正確的話,你要一個屬性(這裏的按鈕.Value屬性)設爲您所有的buttonsswButtons)。

聲明的你的組件陣列,而不是他們的值數組的

Dim swButtons() As DevComponents.DotNetBar.Controls.SwitchButton = _ 
    {sw0, sw1, sw2, sw3, sw4, sw5, sw6, sw7, sw8, sw9, sw10, sw11} 

然後你就可以輕鬆地重複這樣的:

For Each item As DevComponents.DotNetBar.Controls.SwitchButton In swButtons 
    item.Value = True 
Next 

或者,如果您想要根據索引更改循環中一個按鈕的單個值你可以這樣訪問按鈕:

swButtons(q).Value = True 
+0

非常感謝您的信息。我想通過申請來達到他們所說的目標。我很抱歉我的英語不好。對自己好。 – brooqs