मेरे पास एक वीबी है।नेट टूलस्ट्रिप जिसमें मैं प्रोग्रामेटिक रूप से बटन जोड़ता हूं। कुछ बटन चेक किए गए हैं या अनचेक किए गए राज्य के आधार पर जब उपयोगकर्ता ने आखिरी बार एप्लिकेशन सेट किया था (रजिस्ट्री में संग्रहीत मानों से:
Dim OneButton As New ToolStripButton("T", Nothing, Nothing, "Thailandr")
OneButton.CheckOnClick = True
AddHandler OneButton.Click, AddressOf ClickHandlerLayers
tsLayers.Items.Add(OneButton)
If GetSetting(IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath), "Settings", "ThailandSetting", False) Then
OneButton.PerformClick()
End If
OneButton = New ToolStripButton("W", Nothing, Nothing, "World")
OneButton.CheckOnClick = True
AddHandler OneButton.Click, AddressOf ClickHandlerLayers
tsLayers.Items.Add(OneButton)
If GetSetting(IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath), "Settings", "WorldSetting", False) Then
OneButton.PerformClick()
End If
सबकुछ ठीक काम करता है सिवाय इसके कि मैं बचाना चाहता हूंजब उपयोगकर्ता लागू बटन पर क्लिक करता है तो बटन के मान रजिस्ट्री में वापस आते हैं। मैं कठोर कोडिंग के बजाय tsLayers टूलस्ट्रिप के माध्यम से लूपिंग करके मानों को सहेजना चाहता हूं (जो संभव है, लेकिन जब मैं अधिक बटन जोड़ता हूं तो अतिरिक्त काम होता है)। अब तक मैं नाम देख सकता हूं
" Save which background layers are to be used
For Each tb As ToolStripItem In tsLayers.Items
Debug.Print(tb.Name)
Debug.Print(tb.GetType.ToString)
Debug.Print(tb.Selected)
Debug.Print(tb.Pressed)
Next
परिणाम हैं:
Thailand
System.Windows.Forms.ToolStripButton
False
False
World
System.Windows.Forms.ToolStripButton
False
False
यहां तक कि यदि परिणामों को देखने के समय बटनों में से एक दबाया / चेक किया जाता है। मैं किसी अन्य संपत्ति को नहीं देख सकता जो मेरी मदद कर सकता है, न ही कोई संग्रह जिसे मैं बुला सकता हूं।
टूलस्ट्रिप के माध्यम से लूपिंग द्वारा टूलस्ट्रिप में टूलस्ट्रिपबटन के चेकस्टेट को निर्धारित करने का कोई तरीका है?
उत्तर:
जवाब के लिए 0 № 1कास्ट करें ToolStripItem
के रूप में ToolStripButton
और आप तक पहुंच होगी CheckState
संपत्ति
If tb.GetType Is GetType(ToolStripButton) Then
Dim tbCast As ToolStripButton = DirectCast(tb, ToolStripButton)
Debug.Print(tbCast.CheckState)
End If