473,320 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 3397
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

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

Similar topics

8
by: CJack | last post by:
hy, I have an mdi application, i create a child form and I want to know when a button is pressed while that child form is loaded. I have this code: private void frmTestBaby_KeyUp(object sender,...
2
by: Jim Shank | last post by:
I am really trying to find the best OOP way of doing this. I have a parent MDI form with multiple children and I am trying to communicate variables between them. I have been able to successfully...
6
by: Edwinah63 | last post by:
Hi everyone, could someone give me some thoughts on the best way to manage mdi parent and child forms? in vb6 i could scroll through the forms collection and determine which forms were...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
0
by: Scott H. | last post by:
I have an MDI parent form that creates mdi child forms each of which are represented by a tab item. I use a third party control to generate the tabbed MDI child forms. Each tab or MDI child form...
2
by: Matt | last post by:
Ok here is my problem: I have a MDI parent form called "Main" that I declare in a public module when I start up my program. This form holds the drop down menu that allows my users to access all...
13
by: Academic | last post by:
I have a MDI form, sometimes child forms and sometimes forms that are neither If I close the app the child forms closing and closed event happens followed by the Mdi form receiving the...
4
by: VIKKI | last post by:
hi I want to know different types way for calling child forms in a particular project.....I'm new to C# language and I'm not able to add child form in my project so plz anyone can tell me how to...
12
by: Phil | last post by:
I can check for MdiChildren.Length=0, but which event handler should I put this in to detect when a child window is closed? TIA Phil.
0
by: emalcolm_FLA | last post by:
Hello and TIA for any help with this non profit Christmas assistance project. I have an applicant (app history) and child (child history) tables (4 total). I need to grab the next available (in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.