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
Solved

How can I close the opened form programmatically?

Posted on 2006-11-21
5
265 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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 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