469,332 Members | 6,650 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

VB.NET HELP required on MDI child forms

Mdi Container - frmMdiContainer
Child Form - frmChildForm

however in my frmChildForm, i have a button to open another form - frmSpecial. In order to open frmSpecial in the frmMdiContainer (like a child like frmChildForm). This is what i did in my frmChildForm.
Expand|Select|Wrap|Line Numbers
  1. Dim frmSpecial AS SpecialForm
  2.  
  3. frmSpecial.MdiParent = Me.MdiParent
  4. frmSpecial.WindowState = FormWindowState.Maximized
  5. frmSpecial.Show()
  6. ' More Codes to be executed after frmSpecial closes '
  7. MessageBox.show("frmSpecial shld be close")
  8. ' More Codes to be executed after frmSpecial closes '
The problem is, the frmSpecial shows and disappears immediately and the messagebox pops up. This is not what i wanted.

How can I make the frmSpecial modal in the mdi container? showdialog() does not work. The messagebox shld pop up after i have close the frmSpecial. But currently it opens and closes itself immediately. I need the frmSpecial to stay open after frmSpecial.Show() as i need to fill up information in the form and use in my frmChildForm.
Nov 21 '08 #1
4 3233
nukefusion
221 Expert 100+
To get your message box to pop up after frmSpecial closes you will need to handle the FormClosed event. Some code like the following should work:

Expand|Select|Wrap|Line Numbers
  1.  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim specialForm As frmSpecial
  3.         specialForm = New frmSpecial()
  4.         specialForm.MdiParent = Me.MdiParent
  5.         specialForm.WindowState = FormWindowState.Maximized
  6.         AddHandler specialForm.FormClosed, AddressOf specialForm_FormClosed
  7.         specialForm.Show()
  8.     End Sub
  9.  
  10.     Private Sub specialForm_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
  11.         ' Codes to be executed after frmSpecial closes
  12.         MessageBox.Show("Test")
  13.     End Sub
I don't think there's any way you can set frmSpecial to be a "modal" MDI child but you can simulate that behaviour by looping all MDI children and setting them to "Enabled = false". Then in the FormClosed event where you show the message box, loop all children again and set them to "Enabled = true".
Nov 21 '08 #2
Mdi Container - frmMdiContainer
Child Form - frmChildForm

however in my frmChildForm, i have a button to open another form - frmSpecial. In order to open frmSpecial in the frmMdiContainer (like a child like frmChildForm). This is what i did in my frmChildForm.
Expand|Select|Wrap|Line Numbers
  1. Dim frmSpecial AS SpecialForm
  2.  
  3. frmSpecial.MdiParent = Me.MdiParent
  4. frmSpecial.WindowState = FormWindowState.Maximized
  5. frmSpecial.Show()
  6. ' More Codes to be executed after frmSpecial closes '
  7. MessageBox.show("frmSpecial shld be close")
  8. ' More Codes to be executed after frmSpecial closes '
The problem is, the frmSpecial shows and disappears immediately and the messagebox pops up. This is not what i wanted.

How can I make the frmSpecial modal in the mdi container? showdialog() does not work. The messagebox shld pop up after i have close the frmSpecial. But currently it opens and closes itself immediately. I need the frmSpecial to stay open after frmSpecial.Show() as i need to fill up information in the form and use in my frmChildForm.
Nov 24 '08 #3
nukefusion
221 Expert 100+
You are correct. Execution won't stop at the specialForm.Show() method. The form is shown and the program keeps on running.
If you use ShowDialog() then execution will pause at that point (as you were expecting) until the form closes, but as you pointed out ShowDialog() won't work for what you are trying to do.

To get those two lines of code to run after specialForm is closed, you need to put them inside the FormClosed event, like in the following sample:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
  2.         Dim specialForm As frmSpecial 
  3.         specialForm = New frmSpecial() 
  4.         specialForm.MdiParent = Me.MdiParent 
  5.         specialForm.WindowState = FormWindowState.Maximized 
  6.         AddHandler specialForm.FormClosed, AddressOf specialForm_FormClosed 
  7.         specialForm.Show() 
  8.     End Sub 
  9.  
  10.     Private Sub specialForm_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs) 
  11.         ' Codes to be executed after frmSpecial closes 
  12.   textbox.text = specialForm.object.name
  13. getNumber(specialForm.object.number)
  14. End Sub 
Nov 24 '08 #4
ok i see how it works now. thanks nukefusion!
Nov 27 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Edwinah63 | last post: by
reply views Thread by Scott H. | last post: by
4 posts views Thread by VIKKI | last post: by
reply views Thread by emalcolm_FLA | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.