且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Display 4 Flash从根目录一个接一个地添加

更新时间:2022-10-18 10:28:53

这段代码非常严峻.除了丑陋的其他方式之外,您还没有在电影结束时捕捉到事件,这意味着电影的播放时间将与您的计时器一样长,而不是从头到尾.您是否尝试逐步解决?我也看不到您指定计时器持续时间的任何地方.您需要进行更多调试,然后根据您自己的发现向我们提出更具体的问题.


hi this is Krishna
I have a windows application which plays image and flash ads.i used three timers to play these ads.for example my folder contains 1.swf,2.jpg,3.jpg,4.swf,5.swf,.....
here i am using if condition.but i wanted to use like if extention is .swf then it has to use timer1 and play flash add.if the next files extention is .jpg then it has to use timer2 how to do that.

my code is like below:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Demo_Flash
{
    public partial class Form1 : Form
    {
        Timer timer1 = new Timer();
        Timer timer2 = new Timer();
        Timer timer3 = new Timer();

        int i = 0;
        int j = 0;
        public Form1()
        {
            InitializeComponent();
            i = 1;
            j = 1;
            timer1.Tick += new EventHandler(timer1_Tick);
            timer1.Interval = (1000) * 10;
            timer1.Enabled = true;
            timer1.Start();

            timer2.Tick += new EventHandler(timer2_Tick);
            timer2.Interval = (1000) * 10;
            timer2.Enabled = false;
            
            timer3.Tick += new EventHandler(timer3_Tick);
            timer3.Interval = (1000) * 5;
            timer3.Enabled = true;
            timer3.Start();            
        }

        void timer1_Tick(object sender, EventArgs e)
        {
            pictureBox1.Visible = false;
            pictureBox1.Enabled = false;
            axShockwaveFlash1.Visible = true;
            axShockwaveFlash1.BringToFront();
  
            if (i == 1)
            {
                string path = System.Environment.CurrentDirectory;
                path += @"\Top_1.swf";
                axShockwaveFlash1.LoadMovie(0, path);
                axShockwaveFlash1.Play();
                i++;
            }
            else if (i == 2)
            {  
                string path = System.Environment.CurrentDirectory;
                path += @"\Top_2.swf";
                axShockwaveFlash1.LoadMovie(0, path);
                axShockwaveFlash1.Play();
                i--;
            }
 
        }

        void timer2_Tick(object sender, EventArgs e)
        {
            axShockwaveFlash1.Visible = false;
            pictureBox1.BringToFront();
            pictureBox1.Visible = true;
            pictureBox1.Enabled = true;
            
            if (j == 1)
            {        
                pictureBox1.Image = Image.FromFile("D:/Project Source/Experimented/Bulk Sms/ProjectSms/ProjectSms/bin/Debug/Advertisement1_1.jpg");
                j++;
            }
            else if (j == 2)
            {
               pictureBox1.Image = Image.FromFile("D:/Project Source/Experimented/Bulk Sms/ProjectSms/ProjectSms/bin/Debug/Advertisement2_1.jpg");
                j--;
            }
        }

        void timer3_Tick(object sender, EventArgs e)
        {
            timer3.Enabled = false;
            timer2.Enabled = true;
            timer2.Start();
        }
    }
}



Note:
the code above may be wrong i am not an expert in C#
my thing is simple like below:

1.i have windows form i have to display some(flash or images) adds on it from root directory(or a particular directory say D:\Images)
with certain intervals(ex:8 sec)
the directory may contain flash or images i have to display both on same location (for example first add is flash and second add is image then first my form display flash after 8 seconds it display image the loop is continued regardless of weather it is a image or flash) then what i have to do

This code is pretty grim. Apart from the other ways that it''s ugly, you''re not catching an event for the end of a movie, which means it will play for as long as your timer, not from beginning to end. Have you tried stepping through it ? I also don''t see anywhere that you specify a duration for the timer. You need to do some more debugging and ask us a more specific question based on what you find out for yourself.