rmiller1981
New member
- Joined
- Aug 1, 2009
- Messages
- 4
- Programming Experience
- 1-3
I have a MDI based application
with two problems.
First: when i close the MDI child i want to ask if the user would like to save the data in the child and give them the regular choice yes,no,cancel however when i try to use the Formclosing event it never fires, it does fire for the mdi parent but that is no help.
Second: When i load the child i am using a template form to get all the controls and code, but if i close all the children then reopen one it errors because the controls are disposed.
Can anyone help solve these problems? I am including some of the code i am having errors with!
with two problems.
First: when i close the MDI child i want to ask if the user would like to save the data in the child and give them the regular choice yes,no,cancel however when i try to use the Formclosing event it never fires, it does fire for the mdi parent but that is no help.
Second: When i load the child i am using a template form to get all the controls and code, but if i close all the children then reopen one it errors because the controls are disposed.
Can anyone help solve these problems? I am including some of the code i am having errors with!
VB.NET:
' The code to create the new child forms:
Private m_ChildFormNumber As Integer
Dim new_controls(Child_Form_template.Controls.Count) As Control
Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click
' Create a new instance of the child form.
Dim ChildForm As New System.Windows.Forms.Form
' set the layout of the child form.
ChildForm.Controls.AddRange(new_controls)
ChildForm.CausesValidation = True
' Make it a child of this MDI form before showing it.
ChildForm.MdiParent = Me
m_ChildFormNumber += 1
ChildForm.Text = "Question " & m_ChildFormNumber
ChildForm.Show()
End Sub
Private Sub Main_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Child_Form_template.Controls.CopyTo(new_controls, 0)
End Sub
' The code for the formclosing event:
Private Sub Child_Form_template_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If saved_status = 0 Then
Dim save_now As MsgBoxResult = MsgBox("Question not saved, Would you like to save now?", MsgBoxStyle.YesNoCancel, "Save Question?") = MsgBoxResult.Yes
If save_now = MsgBoxResult.Yes Then
Save_Question()
ElseIf save_now = MsgBoxResult.Cancel Then
e.Cancel = True
End If
End If
End Sub