Solved

Can Not Close Second Child Form

Posted on 2009-07-05
10
206 Views
Last Modified: 2012-05-07
Hi,

I call 2nd Child Form from 1st Child Form.
At 1st Child Form Closing,  I try to close 2nd Child Form using:

   With frmSecondChild
            .Close()
            .Dispose()
        End With

But it does not close the form.

Why is it?

Thank you.
0
Comment
Question by:emi_sastra
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 24782309
Is frmSecondChild the Type of the Form?...or is this a variable?

In other words, are you using the "default instance" of the form or creating an instance manually?

I'm guessing that your showing an instance of the form using the "new" keyword but closing the default instance.

Show us some code on how you open the second child form...
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 24782317
Please my code

Thank you.


If ERV_Global.Form_Active("frmMISBROWSELABARUGI", Me) Then
 
            With frmMISBROWSELABARUGI
                .strMonth = txtFromMonth.Text
                .strYear = txtFromYear.Text
                .strAccNo = dgvHeader.CurrentRow.Cells("AccNo").Value.ToString.Trim
                .strAccount = .strAccNo & ERV_Global.glbComboSeparator & dgvHeader.CurrentRow.Cells("Name").Value.ToString.Trim
                .lblTotaBulan.Text = txtTotalMonth.Text
 
                .Open_Data()
            End With
        Else
            Dim frmMISBROWSELABARUGI As New frmMISBROWSELABARUGI
 
            With frmMISBROWSELABARUGI
                .strMonth = txtFromMonth.Text
                .strYear = txtFromYear.Text
                .strAccNo = dgvHeader.CurrentRow.Cells("AccNo").Value.ToString.Trim
                .strAccount = .strAccNo & ERV_Global.glbComboSeparator & dgvHeader.CurrentRow.Cells("Name").Value.ToString.Trim
                .lblTotaBulan.Text = txtTotalMonth.Text
 
                .Show(Me)
            End With
 
        End If

Open in new window

0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24782336
The answer will depend on how you create the instance of the form.

If you create the form this way

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

Dim frmSecondChild as new Form2 '<-- First instance...

frmSecondChild.Show

End Sub

Then you try to close it this way in the form1 closing event then...

Dim frmSecondChild as new form2 '<-- Second Instance...

With frmSecondChild
            .Close()
            .Dispose()
        End With


You really can't close the form, becuase you create two instance of form2.


So to close the form do this instead....


Private frmSecondChild as form2

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

frmSecondChild = new Form2 '<-- First instance...

frmSecondChild.Show

End Sub

Then on the form1Closing event do this:


With frmSecondChild
            .Close()
            .Dispose()
End With
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 15

Accepted Solution

by:
JackOfPH earned 500 total points
ID: 24782342
but if you still want to stick with your code.... you can do this...


With System.Windows.Forms.Application.OpenForms("frmMISBROWSELABARUGI")
       .Close()
       .Dispose()
End With
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 24782345
Hi JackOfPH,

Please see my code above.

What's wrong with it?

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 24782359
Hi JackOfPH,

It works.

Thank you very much for your help.
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24782364
Dim frmMISBROWSELABARUGI As New frmMISBROWSELABARUGI

This line of code...

As I have said you where only creating an instance of the form that only accessible to that particular Function or Sub.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 24782378
Is there other way to create it, thus it could be recognize by other sub?
How to declare the form ?

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 24782383
I see your comment, using:

Private frmSecondChild as form2

Which one is better?

Using  the above code or With System.Windows.Forms.Application.OpenForms("frmMISBROWSELABARUGI")

Thank you.
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24782390
There are two possible way,

The first way is the one I gave you...

System.Windows.Forms.Application.OpenForms("frmMISBROWSELABARUGI")

then the second way is to declare a Private variable.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question