Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can I close the opened form programmatically?

Posted on 2006-11-21
5
Medium Priority
?
274 Views
Last Modified: 2010-04-23
How can I close the opened form programmatically?

Here is what i do

Public class Form1

Dim frm as form2


Private sub ShowForm()

for ctr as integer = 0 to 5

frm = new form2

frm.text = "opened " & ctr

frm.show

next

End Sub



end class




Now, how can I close the form that has the text (caption) = "opened 3" when I click the button on form1?
0
Comment
Question by:JackOfPH
  • 3
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
Solar_Flare earned 2000 total points
ID: 17992584
you want to keep references to the forms that you create, say put them in an arraylist



Public class Form1


dim ChildForms as arraylist


Private sub ShowForm()

childforms = new arraylist
for ctr as integer = 0 to 5

dim frm as new form2
childforms.add(frm)
frm.text = "opened " & ctr

frm.show

next

End Sub

end class

now you can look through childforms and find the form that you want.
0
 
LVL 15

Author Comment

by:JackOfPH
ID: 17992849
How?

Sorry, I am new to vb.net... :)
0
 
LVL 15

Author Comment

by:JackOfPH
ID: 17992860
>>now you can look through childforms and find the form that you want.

How can I do this? Can you rpovide me with some sample code?
0
 
LVL 15

Author Comment

by:JackOfPH
ID: 17992928
Got it....
Thanks....

Dim temp As Object
        For ctr As Integer = 0 To ChildForms.Count - 1

            temp = ChildForms.Item(ctr)
            If temp.text = "opened 3" Then
                temp.close()
            End If
        Next
0
 
LVL 15

Expert Comment

by:Solar_Flare
ID: 17997999
yep that will do it,

you can also use a for each loop

 For each f as Form2 in childforms
   if f.text = "opened 3" then f.close()
 Next
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

971 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