Solved

How to kill a form

Posted on 2006-11-18
5
209 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
[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
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 143

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

688 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