schenkp
asked on
NEED HELP ASAP
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?
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.
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?
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
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
ASKER
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(DateTi me.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.Time r)sender;
myTimer.Stop();
progressBar1.Value = progressBar1.Maximum;
shutDown();
toolStripStatusLabel1.Fore Color = Color.Red;
toolStripStatusLabel1.Text = "Cycle Completed....";
this.fluidEffect1.ImageBit map = (System.Drawing.Bitmap)Sys tem.Drawin g.Image.Fr omFile("C: \\Cycle Completed.jpg");
fluidEffect1.RenderDrop(75 , 75, 250);
timer3.Enabled = false;
}
}
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(DateTi
if (ts.TotalMilliseconds > 0)
{
toolStripStatusLabel2.Text
progressBar1.Value = (int)(progressBar1.Maximum
}
else
{
System.Windows.Forms.Timer
myTimer.Stop();
progressBar1.Value = progressBar1.Maximum;
shutDown();
toolStripStatusLabel1.Fore
toolStripStatusLabel1.Text
this.fluidEffect1.ImageBit
fluidEffect1.RenderDrop(75
timer3.Enabled = false;
}
}
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 ...
}
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.
ec4.Owner = this;
}
public void Shutdown()
{
ec4.Close();
}
... all your other code ...
}
ASKER
Andy,
Actualy there are four form that I need to shutdown they are
EC45
EC135
EC225
EC315
Actualy there are four form that I need to shutdown they are
EC45
EC135
EC225
EC315
Are you shutting them all down at the same time, or do they all get shut down at different times?
ASKER
they are being shut down at the same time, but i can even get it to work with one of them.
Did you try to close the form in the EC45 ? Try to play with easy form without any playable media.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I would rather not post the full code here but I am willing to email you the project, just need your email address.
ASKER
Got your code to work perfectly on my test machine.
ASKER
Got it.... had to change the IsMdiContainer property to true...
Thanks for your help....
Thanks for your help....
Glad you got it working.
Andy
Andy
Andy