VB6에서 VB.NET으로 일부 기존 코드를 마이그레이션 중이므로 성가신 문제가 발생했습니다. 현재 어떤 일이 일어나고 있는지 사용자에게 RadionButton
컨트롤이 제공되어 계층 구조를 나타냅니다. 그들이 값을 선택할 때 코드는 그것이 유효하다는 것을 확인합니다 (C가 A의 자손이 될 수없고 B의 자이어야 함). 그렇지 않으면 RadioButton
을 원래 설정으로 되돌립니다.이벤트에서 RadioButton checkstate를 변경하십시오.
문제는이 작업을 이벤트 처리기로 반환하면 클릭했을 때의 상태로 RadioButton
상태를 반환합니다 (사용자가 C를 클릭하면 코드가 B로 반환되고 함수가 종료하면 C로 반환 됨). 무한 루프를 일으키는 이벤트를 발생시켜 다시 B로 바꾼다. RadioButton is selected inside a function called by
CheckedChanged` 이벤트를 변경하는 방법이 있습니까?
내가 더 좋은 디자인은 유효하지 않은 컨트롤을 사전에 무효화하는 것임을 알고 있지만 이것은 설계된 방법이며 제한된 시간 프레임에서 작업하는 것이므로 나쁜 디자인으로 붙어 있습니다. 나중에 좋은 디자인에 반대했다.
코드 :
Private Sub optIndent_2_ClickEvent(sender As Object, e As EventArgs) Handles optIndent_2.CheckedChanged
optIndent_Click(2, sender.Checked)
End Sub
Private Sub optIndent_3_ClickEvent(sender As Object, e As EventArgs) Handles optIndent_3.CheckedChanged
optIndent_Click(3, sender.Checked)
Dim i As Integer = 1
End Sub
Private Sub optIndent_Click(ByRef Index As Short, ByRef value As Short)
If value = False Then
Exit Sub
End If
If Index = 2 Then
Exit Sub
End If
If Index = 3 Then
optIndent_2.Checked = True
Exit Sub
End If
End Sub
당신은 코드가 optIndent_Click (3, sender.checked)
종료 할 때 값이 false에서 true로 전환 할 것을 볼 수 있습니다, 프로세스는 영원히 반복합니다.
이 대신 당신이 ByVal를 사용해야합니다 :Specifies that an argument is passed in such a way that the called procedure can change the value of a variable underlying the argument in the calling code.
Specifies that an argument is passed in such a way that the called procedure or property cannot change the value of a variable underlying the argument in the calling code.
문제를 해결하는 ByVal
인수로 인수 value
변경