Ключевым моментом здесь является добавление подпрограммы, которая проверяет флажки. Вам понадобится этот саб, потому что он будет вызываться несколько раз в зависимости от действий пользователя.
Поскольку вы не предоставляете никаких сведений о tmpView и vpList, я буду придерживаться вашего кода, однако вам следует помнить, что в зависимости от того, что именно вы пытаетесь сделать, ваш код может быть упрощен или переписан, чтобы быть немного более эффективным. Например, вы не указываете, хотите ли вы, чтобы значение tmpVP было уникальным в списке или было более одного раза, я предполагаю, что вы хотите быть уникальным, поэтому вот код сабвуфера (пожалуйста, прочитайте комментарии в коде ):
Private Sub CheckBoxesStatus(StructcheckBoxChecked As Boolean, LegcheckBoxChecked As Boolean)
If StructcheckBoxChecked Then
If tmpView.ViewType = ViewType.EngineeringPlan Then
'Add code here to check if the tmpVP element is already in the vpList
'and add it only if there isn't otherwise it will be added each time the
'StructcheckBox is checked by the user...
'An example code is as follows:
If Not vpList.Contains(tmpVP) Then vpList.Add(tmpVP)
End If
End If
If LegcheckBoxChecked Then
If tmpView.ViewType = ViewType.Legend Then
'Add code here to check if the tmpVP element is already in the vpList
'and add it only if there isn't otherwise it will be added each time the
'LegcheckBox is checked by the user...
'An example code is as follows:
If Not vpList.Contains(tmpVP) Then vpList.Add(tmpVP)
End If
End If
End Sub
Теперь, когда у вас есть сабвуфер, вы можете вызывать его, когда захотите. «Всякий раз, когда вы хотите» означает действия различных пользователей, такие как установка или снятие флажка, а также в других местах, таких как инициализация (загрузка) формы, это события. По вашему вопросу вам нужно позвонить из 3 разных событий.
1.При загрузке формы для получения начального статуса:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
CheckBoxesStatus(StructcheckBox.Checked, LegcheckBox.Checked)
End Sub
2. Когда пользователь изменяет статус StructcheckBox:
Private Sub StructcheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles StructcheckBox.CheckedChanged
CheckBoxesStatus(StructcheckBox.Checked, LegcheckBox.Checked)
End Sub
3. Когда пользователь меняет статус LegcheckBox:
Private Sub LegcheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles LegcheckBox.CheckedChanged
CheckBoxesStatus(StructcheckBox.Checked, LegcheckBox.Checked)
End Sub
Вот полный код формы:
Public Class Form1
Private Sub CheckBoxesStatus(StructcheckBoxChecked As Boolean, LegcheckBoxChecked As Boolean)
If StructcheckBoxChecked Then
If tmpView.ViewType = ViewType.EngineeringPlan Then
'Add code here to check if the tmpVP element is already in the vpList
'and add it only if there isn't otherwise it will be added each time the
'StructcheckBox is checked by the user...
'An example code is as follows:
If Not vpList.Contains(tmpVP) Then vpList.Add(tmpVP)
End If
End If
If LegcheckBoxChecked Then
If tmpView.ViewType = ViewType.Legend Then
'Add code here to check if the tmpVP element is already in the vpList
'and add it only if there isn't otherwise it will be added each time the
'LegcheckBox is checked by the user...
'An example code is as follows:
If Not vpList.Contains(tmpVP) Then vpList.Add(tmpVP)
End If
End If
End Sub
Private Sub StructcheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles StructcheckBox.CheckedChanged
CheckBoxesStatus(StructcheckBox.Checked, LegcheckBox.Checked)
End Sub
Private Sub LegcheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles LegcheckBox.CheckedChanged
CheckBoxesStatus(StructcheckBox.Checked, LegcheckBox.Checked)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
CheckBoxesStatus(StructcheckBox.Checked, LegcheckBox.Checked)
End Sub
End Class
Надеюсь, это поможет.