Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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
Posted
Updated 12-Jul-10 1:46am
v7

1 solution

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.
 
Share this answer
 
Comments
krishna_goluguri 8-Jul-10 4:55am    
mine is simple thing
1.i have windows form i have to display some(flash) adds on it from root directory
with certain intervals(ex:8 sec)then what i have to do

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900