Solved

How can I close the opened form programmatically?

Posted on 2006-11-21
5
263 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 500 total points
Comment Utility
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
Comment Utility
How?

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

Author Comment

by:JackOfPH
Comment Utility
>>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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now