943,576 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 953
  • VB.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
May 23rd, 2009
0

MDI Issues

Expand Post »
I have two Issue using a MDI app.
1-at this moment I'm able to open MDI child forms using the MDIparent
except when the I opens form1 I'm also able to open forms 2
and 3 .
but I only want one form to be open at a time.
2- The next issue is I have form 2 to be opened from form1 and I would like to close form2 and form1 when click close on form2. At this moment I have to close form2 then click close on form1.

Thank you
code for Q1 This is the code on the MDIparent to open the forms.
VB.NET Syntax (Toggle Plain Text)
  1. Public Sub tbbCustomer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbbCustomer.Click
  2. Dim CustomerMDIChild As New CustumerRprt()
  3. CustomerMDIChild.MdiParent = Me
  4. CustomerMDIChild.Show()
  5. CustomerMDIChild.Location = New Point(Me.Width / 2 - CustomerMDIChild.Width / 2, Me.Height / 2 - CustomerMDIChild.Height / 2)
  6. End Sub

Q2 here is he code I tried to close form2 and form1.

VB.NET Syntax (Toggle Plain Text)
  1. Public Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
  2.  
  3. If m_ID = 0 Then
  4. Me.Close()
  5. Else
  6. CustumerRprt.Close()
  7. Me.Close()
  8. End If
  9. End Sub
Similar Threads
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
VIPER5646 is offline Offline
83 posts
since Mar 2009
May 25th, 2009
0

Re: MDI Issues

use a loop that will check the mdichild's forms then close them and then open the form you wanted to open...
VB.NET Syntax (Toggle Plain Text)
  1. For Each frm As Form In Me.MdiChildren
  2. frm.Close()
  3. Next
  4.  
  5. Dim frm1 As Form1
  6. frm1.Show
Reputation Points: 11
Solved Threads: 49
Posting Whiz
jireh is offline Offline
316 posts
since Jul 2007
May 25th, 2009
0

Re: MDI Issues

Click to Expand / Collapse  Quote originally posted by VIPER5646 ...
I have two Issue using a MDI app.
1-at this moment I'm able to open MDI child forms using the MDIparent
except when the I opens form1 I'm also able to open forms 2
and 3 .
but I only want one form to be open at a time.
try to use ShowDialog() instead of Show() or check for TopMost = True
Reputation Points: 69
Solved Threads: 19
Junior Poster
samir_ibrahim is offline Offline
155 posts
since Sep 2008
May 25th, 2009
0

Re: MDI Issues

Thanks Jireh and samir_ibrahim for your replies.
The first Issue has been solved.
I still need more help with the second Issue.
This is the coed I used to open form1.
VB.NET Syntax (Toggle Plain Text)
  1. For Each Form In Me.MdiChildren
  2. Form.Close()
  3. Next
  4. Dim CustomerMDIChild As New CustumerRprt()
  5. CustomerMDIChild.MdiParent = Me
  6. CustomerMDIChild.Show()
This coed opens form2.
VB.NET Syntax (Toggle Plain Text)
  1. Design_Report.Show()
How can I close form2 and form1 by just closing form2
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
VIPER5646 is offline Offline
83 posts
since Mar 2009
May 26th, 2009
0

Re: MDI Issues

For Q2:
In form2, use the FormClosing event to close form1, then form2 will close after.
VB.NET Syntax (Toggle Plain Text)
  1. Private Sub Form2_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
  2. Form1.close
  3. End Sub

-Zander
Last edited by Zandermander; May 26th, 2009 at 5:21 pm.
Reputation Points: 10
Solved Threads: 1
Light Poster
Zandermander is offline Offline
30 posts
since Oct 2008
May 26th, 2009
0

Re: MDI Issues

I have tried your code but I'm still unsuccessful. Still can't close form1. form2 closes but not form1.
When I click the Close button it jumps to the closing sub (your code)
but does not close form 1.
Help
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
VIPER5646 is offline Offline
83 posts
since Mar 2009
May 27th, 2009
0

Re: MDI Issues

Is form1 set to the form that ends the app?
if it is, try Application.Exit in the form2 closing event.

-Zander
Reputation Points: 10
Solved Threads: 1
Light Poster
Zandermander is offline Offline
30 posts
since Oct 2008
May 27th, 2009
0

Re: MDI Issues

Click to Expand / Collapse  Quote originally posted by VIPER5646 ...
I have tried your code but I'm still unsuccessful. Still can't close form1. form2 closes but not form1.
When I click the Close button it jumps to the closing sub (your code)
but does not close form 1.
Help
I had tried this and works with me.

VB.NET Syntax (Toggle Plain Text)
  1. 'in form2.button_click
  2. Me.Close()
  3. Form1.Close()
Reputation Points: 69
Solved Threads: 19
Junior Poster
samir_ibrahim is offline Offline
155 posts
since Sep 2008
May 27th, 2009
0

Re: MDI Issues

Thank you for your replies but it still isn't solved.
To Zandermander your code worked but it closes the entire appl. and I only want form1 and 2 to close.
To Samir_Ibrahim yes I have tried your coed and it did not work.
It closes only form1 but it does not close form2
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
VIPER5646 is offline Offline
83 posts
since Mar 2009
May 28th, 2009
0

Re: MDI Issues

Ok.. well try form1.hide maybe.. it doesn't "close it" but it should make it non visable.. can't test it right not.. on my phone when I get to my computer ill try some more things... though im not sure why form1.close won't work...

maybe use the code
VB.NET Syntax (Toggle Plain Text)
  1. form2.button_click
  2. Me.Close()
  3. Form1.Close()

but switch form1.close and me.close

sorry if there are errors in this post. once again.. on my phone.

-Zander
Reputation Points: 10
Solved Threads: 1
Light Poster
Zandermander is offline Offline
30 posts
since Oct 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: WeBrowser1 - blank after 2nd click
Next Thread in VB.NET Forum Timeline: How to load images in win form





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC