2016-08-02 6 views
0

양식로드시 MessageBox를 숨길 수있는 방법이 있습니까?MessageBox를 숨길 방법이 있습니까?

저는 Checkedlistbox을 사용했으며 Form2의 부하에 이미 checkeditems이 있습니다.

내가 원하는 것은 Form1을 클릭하면 Form2Checkedlistbox이 표시됩니다. 내 문제는 Form1을 클릭하면 Form2 앞에 MessageBox가 표시된다는 것입니다. 당신은 내가 또한 checklistbox1을 점검 할 필요가 있음을 알 수 내 코드에서

Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
    chklstBox1Fill() 
End Sub 

Private Sub CheckedListBox1_ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck 
    If e.NewValue = CheckState.Checked Then 
     question = MsgBox("Area you sure you want to remove?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Message") 
     If question = MsgBoxResult.Yes Then 
      'Nevermind 
     ElseIf question = MsgBoxResult.No Then 
      e.NewValue = CheckState.Checked 
     End If 
    End If 
End Sub 

:

Form1 경우 :

Private Sub cmdSubmitModifyQuant_Click(sender As Object, e As EventArgs) Handles cmdSubmitModifyQuant.Click 
    Form2.Show() 
End Sub 

Form2 여기에

내 vb.net에서 코드입니다 .

+2

@ shad0wk : VB.NET에서 양식의 클래스 이름도 기본 인스턴스를 제공하므로 예 컴파일됩니다. –

답변

1

이 문제는 아마도 chklstBox1Fill 메서드에서 사용자가 확인란 목록의 항목을 확인하고있는 것이므로이 확인란을 표시하는 이벤트가 발생합니다. 이를 방지하는 한 가지 방법은 플래그가 설정되어 메시지 상자를 표시하면 채우기있는 목록을 표시하는 플래그를 설정하지하는 것입니다 :

Private FillingList As Boolean 

Private Sub chklstBox1Fill() 
    FillingList = True 

    'Rest of method here. 

    FillingList = False 
End Sub 

Private Sub CheckedListBox1_ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck 
    If FillingList = True Then 
     Return 
    End If 

    If e.NewValue = CheckState.Checked Then 
     question = MsgBox("Area you sure you want to remove?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Message") 
     If question = MsgBoxResult.Yes Then 
      'Nevermind 
     ElseIf question = MsgBoxResult.No Then 
      e.NewValue = CheckState.Checked 
     End If 
    End If 
End Sub 

(내 VB.Net를, 용서 내가 쓴 이후 몇 년이 any).

+0

이것은 나에게 맞는 것처럼 보입니다. 이론적으로이 문제를 해결해야합니다. – David

+0

오. 내 문제가 해결되어야합니다. 고마워,이 세상에 좋은 남자가 있다고. hehehe. – Rhamnold

1

로드 프로 시저가 완료되었는지 여부를 나타내는 부울 변수를 추가하십시오. 이렇게하면 변수가 True로 설정 될 때까지 CheckedChanged이 실행되지 않습니다.

Dim FormLoaded As Boolean = False 

Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
    chklstBox1Fill() 
    FormLoaded = True 
End Sub 

Private Sub CheckedListBox1_ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck 
    If FormLoaded = False Then Return 'Don't execute the rest of the code if it evaluates to False. 

    If e.NewValue = CheckState.Checked Then 
     question = MsgBox("Area you sure you want to remove?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Message") 
     If question = MsgBoxResult.Yes Then 
      'Nevermind 
     ElseIf question = MsgBoxResult.No Then 
      e.NewValue = CheckState.Checked 
     End If 
    End If 
End Sub 
관련 문제