Solved

How can I close the opened form programmatically?

Posted on 2006-11-21
5
267 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
[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
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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