2013-08-29 2 views
0

프로그래밍 방식으로 단추를 추가하는 VB.Net 도구 모음이 있습니다. 일부 버튼은 레지스트리에 저장된 값에서 (그들은 사용자가 마지막 응용 프로그램을 설정할 때 남아 있던 상태에 따라 선택 또는 선택 해제됩니다ToolStrip 루프에서 ToolStripButton CheckState 결정

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 

결과를 볼 때 버튼 중 하나를 누르거나 확인한 경우에도 마찬가지입니다. 나를 도울 수있는 다른 속성이나 내가 파묻을 수있는 컬렉션을 볼 수 없습니다.

툴 스트립을 반복하면서 툴 스트립의 checkstate를 결정하는 방법이 있습니까?

답변

0

캐스트는 A ToolStripButtonToolStripItem하고 CheckState 재산

 If tb.GetType Is GetType(ToolStripButton) Then 
      Dim tbCast As ToolStripButton = DirectCast(tb, ToolStripButton) 
      Debug.Print(tbCast.CheckState) 
     End If 
+0

완벽한에 액세스 할 수 있습니다. 매우 감사합니다. 이제는 줄을 추가하여 전체 도구 모음의 도구 단추 상태를 레지스트리에 저장할 수 있습니다. SaveSetting (IO.Path.GetFileNameWithoutExtension (Application.ExecutablePath), "Settings", tb.Name, tbCast.CheckState) – user2727977

관련 문제