我有一个位于MDI父表单内的自定义选项卡控件。我在选项卡上有一个关闭按钮。单击选项卡关闭按钮时,将删除该选项卡,并删除MDI父窗体的相应MDI子窗体。在MDI子窗体上,我检查其FormClosing事件中的各种条件。如果不满足条件,则通过放置
取消表格的关闭e.Cancel = True
在FormClosing事件中。这一切都有效,但是,当取消表单关闭时,我的选项卡已被删除,我不再有MDI子窗体的相应选项卡。如何从MDI子窗体的FormClosing事件返回Cancel,返回到MDI父窗体上的选项卡控件按钮的关闭事件?
我应该提到选项卡控件不是标准的.net选项卡,它是在标准的.net选项卡控件之上构建的,以允许选项卡上的关闭按钮。我没有为这个自定义选项卡控件编写原始代码。
以下是自定义标签控件' TabControlEx'的类中存在的标签关闭代码。
Public Event CloseButtonClick As CancelEventHandler
Protected Overridable Sub OnCloseButtonClick(ByVal sender As Object, ByVal e As EventArgs)
If Not DesignMode Then
Dim btn As Button = DirectCast(sender, Button)
Dim tp As TabPage = CloseButtonCollection(btn)
Dim ee As New CancelEventArgs
RaiseEvent CloseButtonClick(sender, ee)
If Not ee.Cancel Then
Me.TabPages.Remove(tp)
RePositionCloseButtons()
Me.SelectedIndex = Me.TabCount - 1
End If
End If
End Sub
这是我在MDI父表单上的选项卡控件上使用的代码
Private Sub TabControl_CloseButtonClick(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles TabControl.CloseButtonClick
Dim i As Integer
If TabControl.TabPages.Count > 0 Then
For i = 0 To Me.MdiChildren.Length - 1
If i = TabControl.SelectedIndex Then
Me.MdiChildren(i).Close()
End If
Next
End If
End Sub
这是MDI子窗体上存在的FormClosing代码。我简化了它以显示这种情况
Private Sub frmMyMdiChildForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
If (MsgBox("Do you wan to contiue closing", vbYesNo) = vbNo) Then
e.Cancel = True
'This is where I need to send the cancel command back to the sender somehow
Exit Sub
End If
End Sub