我有三种形式:A,B和C。
单击按钮后,A 显示 B。类似地,B 显示 C。两者都使用 ShowDialog() 方法。
但是,当我在表单 C 上使用 Hide() 方法(在 Button Click 事件中)关闭它时,表单 B 也会关闭。
为什么会这样?据我所知,它不应该这样做。我当然没有编写任何代码来告诉它这样做。
这是代码:
' from Form "A" (MainForm)
Private Sub OrdersDataGridView_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles OrdersDataGridView.CellDoubleClick
ShowViewOrderForm(sender)
End Sub
Private Sub ShowViewOrderForm(ByVal CurrentDGV As DataGridView)
If Not CurrentDGV Is Nothing Then
Dim f As New ViewOrderForm
f.SetOrderNo(CurrentDGV.CurrentRow().Cells().Item(0).Value)
f.SetDeliveryServiceType(CurrentDGV.CurrentRow().Cells().Item(5).Value)
f.ShowDialog()
End If
End Sub
' from Form "B" (ViewOrderForm)
Private Sub IssueOrderButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IssueOrderButton.Click
Dim f As New IssueForm
f.SetOrderNo(ThisOrderNo)
f.ShowDialog()
End Sub
' from Form "C" (IssueForm)
Private Sub CloseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseButton.Click
Me.Hide()
End Sub
更新:我是个白痴。DialogResult
设置为Cancel
按钮上,因为我从现有的关闭按钮复制+粘贴它并且没有意识到该属性已设置。无论如何,谢谢大家的建议!