Solved

NEED HELP ASAP

Posted on 2006-11-18
13
246 Views
Last Modified: 2010-04-16
I am trying to close a form EC45 when a timer runs out.
Cant get this to work, here is the code i am using, EC45 gets 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
Comment
Question by:schenkp
  • 6
  • 6
13 Comments
 
LVL 12

Expert Comment

by:AGBrown
ID: 17972743
Can i clarify this? You have a web form or a windows form?

Andy
0
 
LVL 12

Expert Comment

by:AGBrown
ID: 17972751
Sorry, stupid question.

You have a windows form. Where is the code for the timer located, in the owner form, or the EC45 form? What is the code that starts the timer, and what is the code that executes to kill the form when the timer is at 0?

Andy
0
 

Author Comment

by:schenkp
ID: 17972776
Andy.

The code for the timer is in the main form1.... below is the code that i am trying to use when the timer hits 0.... the timer works fine I just cant get it to close from EC45.

I tried adding this code to the timer thinking it would make the form EC45 close but it does not.

EC45 AX45 = new EC45();
AX45.Close();



        void myTimer_Tick(object sender, EventArgs e)
        {
            TimeSpan ts = targetTime.Subtract(DateTime.Now);
            if (ts.TotalMilliseconds > 0)
            {
                toolStripStatusLabel2.Text = ts.Minutes.ToString("00") + ":" + ts.Seconds.ToString("00");
                progressBar1.Value = (int)(progressBar1.Maximum - ts.TotalSeconds);
            }
            else
            {
                System.Windows.Forms.Timer myTimer = (System.Windows.Forms.Timer)sender;
                myTimer.Stop();
                progressBar1.Value = progressBar1.Maximum;
                shutDown();
                toolStripStatusLabel1.ForeColor = Color.Red;
                toolStripStatusLabel1.Text = "Cycle Completed....";
                this.fluidEffect1.ImageBitmap = (System.Drawing.Bitmap)System.Drawing.Image.FromFile("C:\\Cycle Completed.jpg");
                fluidEffect1.RenderDrop(75, 75, 250);
                timer3.Enabled = false;
               
             }
        }
0
 
LVL 12

Expert Comment

by:AGBrown
ID: 17972794
I'm guessing that shutDown is the method that you are hoping will close the ec45 form?

I suggest that you store the reference to the EC45 form as a class-level field for the main form, and then use that to get the form reference to close when you call Shutdown. This will only fall apart if you can have multiple forms open, at which point we can put another method in place instead.

public class form1
{

EC45 ec4;

public void OpenForm()
{
   ec4 = new EC45();
   ec4.Show();
   ec4.PlayMedia(@"C:\\music.mp3");
   ec4.Owner = this;
}

public void Shutdown()
{
    ec4.Close();
}

... all your other code ...
}
0
 

Author Comment

by:schenkp
ID: 17972843
Andy,
Actualy there are four form that I need to shutdown they are

EC45
EC135
EC225
EC315
0
 
LVL 12

Expert Comment

by:AGBrown
ID: 17972853
Are you shutting them all down at the same time, or do they all get shut down at different times?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:schenkp
ID: 17972880
they are being shut down at the same time, but i can even get it to work with one of them.
0
 
LVL 16

Expert Comment

by:AlexNek
ID: 17972951
Did you try to close the form in the  EC45 ? Try to play with easy form without any playable media.
0
 
LVL 12

Accepted Solution

by:
AGBrown earned 500 total points
ID: 17973073
I have put together a simple form, called Form 1. I have then set its IsMdiContainer property to true, and created a menu item to display an EC45 form. I have dropped a timer onto the designer surface for the form and put the following code in its code file (I am using .NET 2.0). After clicking the menu item to create another EC45 form and show it, one second later that form is closed with the timer. Can you get this to work in a test project on your machine? Also, can you post the full code that you use to create and display your four forms, we should check that targetTime is being set properly (I assume it is if you can see your progress bar counting down), and the full code for your shutDown method.

Andy

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;
using System.Management;
using System.Management.Instrumentation;


namespace WindowsApplicationCS
{
      public partial class Form1 : Form
      {
            EC45 ec4;
            
            public Form1()
            {
                  InitializeComponent();
            }

            private void eC45ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                  ec4 = new EC45();
                  ec4.Show();
                  ec4.Owner = this;
                  this.timer1.Interval = 1000;
                  this.timer1.Enabled = true;
            }

            private void timer1_Tick(object sender, EventArgs e)
            {
                  this.timer1.Enabled = false;
                  ec4.Close();
            }
      }
}
0
 

Author Comment

by:schenkp
ID: 17973092
I would rather not post the full code here but I am willing to email you the project, just need your email address.
0
 

Author Comment

by:schenkp
ID: 17973130
Got your code to work perfectly on my test machine.  
0
 

Author Comment

by:schenkp
ID: 17973145
Got it.... had to change the IsMdiContainer property to true...

Thanks for your help....
0
 
LVL 12

Expert Comment

by:AGBrown
ID: 17974079
Glad you got it working.

Andy
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Parse the OuterHTML Data in the txtfile using c# 4 49
Data is not showing from images 15 38
C# HTTP GET method sample code 3 42
Turn on intranet settings 1 42
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

20 Experts available now in Live!

Get 1:1 Help Now