|
-
Jan 24th, 2014, 06:18 AM
#1
Thread Starter
Junior Member
Detect child form closing from parent form
I have a windows app with a parent form and a child form which opens on click event of a button in parent form.
There is a button OK in child form.
When I press OK child form closes. I want to do some logic on parent form when child form closes immediately.
Can I track down in parent form with the help of any event or property like it was previouspage method in asp.net.
-
Jan 24th, 2014, 06:25 AM
#2
Re: Detect child form closing from parent form
Yes, you can use AddHandler to handle the child form's FormClosing or FormClosed event.
-
Jan 24th, 2014, 06:27 AM
#3
Re: Detect child form closing from parent form
Are you displaying the child form with Show or ShowDialog? Presumably Show but your question suggests that perhaps ShowDialog could be more appropriate. Do you want the user to be able to access the parent even while the child is open?
-
Jan 27th, 2014, 12:38 PM
#4
Thread Starter
Junior Member
Re: Detect child form closing from parent form
I am using ShowDialog to open child form. On click of OK button on child form the form is closed. Now I want to catch in Parent form that the child form is just closed.
Last edited by anuragrawat123; Jan 27th, 2014 at 12:53 PM.
-
Jan 27th, 2014, 12:57 PM
#5
Re: Detect child form closing from parent form
That would then be the next line of code right after the .ShowDialog...
-tg
-
Jan 27th, 2014, 01:12 PM
#6
Thread Starter
Junior Member
Re: Detect child form closing from parent form
I am doing this only. But in child form I have OK, Cancel two buttons.. and i want to differentiate between them when i close child form and reach on parent form.
i.e. which button was clicked on child form.
-
Jan 27th, 2014, 01:27 PM
#7
Addicted Member
Re: Detect child form closing from parent form
On the OK and Cancel buttons on your child form, set their respective DialogResult properties to OK and Cancel, and then from your parent form you can do something like:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim childForm As New Form2
Dim dr As DialogResult = childForm.ShowDialog()
If dr = DialogResult.OK Then
MessageBox.Show("Clicked OK")
Else
MessageBox.Show("Clicked Cancel")
End If
End Sub
-
Jan 27th, 2014, 01:29 PM
#8
Re: Detect child form closing from parent form
Perhaps you could have mentioned that from the start. In the form... your child form. Go to its properties... find the AcceptButton and the CancelButton properties... set them to the appropriate OK & Cancel buttons that are on your form... then in your code in the parent form where you .ShowDialog your form... capture the result of the call to the ShowDialog...
like this:
Code:
Dim myChildForm As New Form3
Dim childResult As DialogResult = myChildForm.ShowDialog()
If childResult = Windows.Forms.DialogResult.OK Then
MessageBox.Show("OK was clicked!")
Else
MessageBox.Show("Cancel was clicked")
End If
-tg
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|