2011-04-07 2 views
0

재귀 적 방법을 사용하여 양식의 모든 구성 요소를 다시 칠하려고합니다. 그러나, 그것은 항상 양식을 recolors 다음 중지됩니다. 어떻게하면이 단계를 지나갈 수 있습니까? 다음은 내가 실험 해본 코드입니다 :VB에서 재귀 회귀

Public Sub fixUIIn(ByRef comp As System.ComponentModel.Component, ByVal style As SByte) 
    Debug.WriteLine(comp) 
    If TypeOf comp Is System.Windows.Forms.ContainerControl Then 
     Dim c As System.Windows.Forms.ContainerControl 
     c = comp 
     c.BackColor = getColor(style, PART_BACK) 
     c.ForeColor = getColor(style, PART_TEXT) 
     If ((comp.Container IsNot Nothing) AndAlso (comp.Container.Components IsNot Nothing)) Then 
      For i As Integer = 0 To comp.Container.Components.Count() Step 1 
       fixUIIn(comp.Container.Components.Item(i), style) 
      Next 
     End If 
     comp = c 
    End If 
    If TypeOf comp Is System.Windows.Forms.ButtonBase Then 
     Dim c As System.Windows.Forms.ButtonBase 
     c = comp 
     c.FlatStyle = Windows.Forms.FlatStyle.Flat 
     c.BackColor = getColor(style, PART_BOX) 
     c.ForeColor = getColor(style, PART_TEXT) 

     comp = c 
    End If 
    If ((comp.Container IsNot Nothing) AndAlso (comp.Container.Components IsNot Nothing)) Then 
     For i As Integer = 0 To comp.Container.Components.Count() Step 1 
      fixUIIn(comp.Container.Components.Item(i), style) 
     Next 
    End If 
End Sub 
+0

comp = 현재 양식을 사용하고 계십니까? 대신 폼의 컨트롤에서 실행 해보십시오. – Toby

+0

예, 그렇습니다. – Supuhstar

답변

1

버튼 컨트롤과 컨테이너 컨트롤의 이름을 변경하는 이유는 무엇입니까? 질문은 "왜"내가 묻는 이유 "all"이라고 말합니다.

나는 또한 이전 VB6 스타일 코드가 사용되는 것을 싫어합니다. 왜 색상 대신 sByte로 색상을 전달하겠습니까? Foreach는 인덱스가있는 for 루프보다 훨씬 간단하게 사용할 수 있습니다. 다음과 같이

나는 이것을 작성합니다

Public Sub FixUIColors(control As Control, foreColor As Drawing.Color, backColor As Drawing.Color) 
    control.BackColor = foreColor 
    control.ForeColor = backColor 
    If TypeOf control Is ButtonBase Then 
     DirectCast(control, ButtonBase).FlatStyle = FlatStyle.Flat 
    End If 

    ' iterate through child controls 
    For Each item In control.Controls 
     FixUIColors(item, foreColor, backColor) 
    Next 
End Sub 

당신이 특정 유형에 제한하려면, 당신은 같은 것을 할 수있는 :

Select Case control.GetType 
     Case GetType(ContainerControl) 
     Case GetType(ButtonBase) 
      control.BackColor = foreColor 
      control.ForeColor = backColor 
    End Select 

내가 style as SByte의 사용에 혼란 스러워요을 PART_BOXPART_TEXT 등입니다. 따라서 원하는대로 정확히 수행하지 않아도됩니다. 나는 이것이 잘못되었다고 생각합니다. System.Drawing.Color를 전달해야합니다. 이유는 나 같은 사람이이 코드를 읽고 이해할 수 있기 때문입니다. 하나의 객체에 여러 색상을 저장하여 쉽게 전달할 수있게하려면 해당 클래스를 저장하는 클래스를 만들 수 있습니다. 한 묶음의 색상에 바이트를 푸는 작업은 다른 기능으로 처리해야하는 작업입니다.

+0

고마워요! 슬프게도, 나는이 질문을했기 때문에 몇 가지 OS를 설치했으며이 대답을 테스트 할 수 없다 : – Supuhstar