Solved

How to kill a form

Posted on 2006-11-18
5
206 Views
Last Modified: 2010-04-16
HI,
If i have a couple of forms open and i would like them to close when the user clicks on a button on the main form, what the best way to do this?
0
Comment
Question by:schenkp
5 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 17971890
On the main form keep a reference to the forms you wish to close then when the user clicks on the button do ReferenceToForm.Close(); Where the ReferenceToForm is the variable name used to reference the form you created.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17971904
vb.net 2003 does not seem to have a forms collection like vb6, while vb.net 2005 does have it:
http://www.dotnet247.com/247reference/msgs/21/107856.aspx
http://www.vbforums.com/showthread.php?t=387971

in depending on the version you are, you will have to manage all your forms, or be able to use
My.Application.OpenForms

0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 17971961
Hi schenkp,

Are your forms children? In this case, you can go through the MDIChildren collection:
        For Each frmChild As Form In Me.MdiChildren
            frmChild.Close()
        Next

Cheers!
0
 

Author Comment

by:schenkp
ID: 17972712
Cant get this to work, here is the code i am using, its get launched when a user selects the menu option...

                EC45 ec4 = new EC45();
                ec4.Show();
                ec4.PlayMedia(@"C:\\music.mp3");
                ec4.Owner = this;

There is a timer in the program and when it counts down to zero I am trying to close EC45 form and its not working?
0
 
LVL 20

Accepted Solution

by:
Daniel Van Der Werken earned 500 total points
ID: 17975169
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        Form2 fm2;  <== the key is to declare the form outside of the function
                                   =================================

        public Form1()
        {
            InitializeComponent();
            comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
            comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;

            comboBox1.DrawMode = DrawMode.OwnerDrawVariable;
            comboBox1.Items.Add("Hello World");
            comboBox1.Items.Add("Wee Willy Wanka");
            comboBox1.Items.Add("Tiffany Aiken");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            fm2 = new Form2();
            fm2.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            fm2.Close();
        }
    }
}
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MediaHelp 4 23
Moving code from one TFS branch to another 3 25
C# bracket error 3 31
C# winforms programmitically move panels 6 29
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 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