1

I have a form contains a shock Wave Flash Object.I want after playing the file or in the middle of it by pressing a key another form is shown.what should I do?should I use an event? I really appreciate somebody who answer it. here the code:

private void Form1_Load(object sender, EventArgs e) {

        axShockwaveFlash1.Movie = "c:/intro.swf";
        axShockwaveFlash1.Forward();
        axShockwaveFlash1.Play();
        Form2 form2 = new Form2();
        form2.Show();
    }

and in form2:

private void Form2_Load(object sender, EventArgs e) {

        Form1 form1 = new Form1();
        form1.Close();
     }

when I debug it both of them are shown but I just want form2


  • How are you playing the SWF? (What object/control are you using?) - Evan Mulawski
  • If axShowckwaveFlash1 has an event for Completed or Finsihed, subscribe to it and show the new form when its done. - Nate
  • I dont think it has such event! - shiny

2 답변


1

You can pass the Form1 instance to the Form2 constructor, and close it there, like:

public Form2(Form1 form1)
{
    InitializeComponents();

    form1.Hide();//hide the control from the user, or close it if it not the main form..
}

Or if you want it to close the form1 instance when a button click then:

private Form1 _form1 = null;
public Form2(Form1 form1)
{
    InitializeComponents();

    _form1 = form1;
}

private void button1_Click(object sender, EventArgs e)
{
    if (_form1 != null)
    {
        _form1.Hide();
    }
}

Initialize the form2 in form1:

axShockwaveFlash1.Movie = "c:/intro.swf";
axShockwaveFlash1.Forward();
axShockwaveFlash1.Play();
Form2 form2 = new Form2(this);//"this here is the form1 instance itself"
form2.Show();


  • thanks Jalal.I use this method but why is the program on progress even if I close form2?and debuging never stop? - shiny
  • Because you didn't close the form1 as will, remember we hide it. so handle the form2 Closing event and close the form1 instance as well. - Jalal Said
  • I did it but no change! - shiny
  • private void Form2_FormClosing(object sender, FormClosingEventArgs e) { Form1 form1 = new Form1(); form1.Close(); } - shiny
  • no, here you are creating a new Form1 and closing it. you should use the other solution : private Form1 _form1 = null; public Form2(Form1 form1) { InitializeComponents(); _form1 = form1; } Form2_FormClosing(object sender, FormClosingEventArgs e) { _form1.Close(); } - Jalal Said

0

you can also use timer to check weather the movie is playing or not,if not then open new form which is form2

 private void flash_Load(object sender, EventArgs e)
    {
        axShockwaveFlash1.Movie = @"C:\Users\Adil M\Documents\Visual Studio 2012\Projects\TProject\a.swf";
        int a = axShockwaveFlash1.MovieData.Length;
        timer1.Start();
    }

now code on timer event

 private void timer1_Tick(object sender, EventArgs e)
    {
        if (!axShockwaveFlash1.IsPlaying())
        {
            Fome2 fobj = new Form2();
            this.Hide();
            timer1.stop();

            fobj.show();

        }
        else if(axShockwaveFlash1.IsPlaying())
        {
        }
    }

this code is working for you only when your movie is complete or for any key you can also do it in timer thanx

Related

Latest