Mostrando entradas con la etiqueta threading. Mostrar todas las entradas
Mostrando entradas con la etiqueta threading. Mostrar todas las entradas

jueves, 24 de marzo de 2011

SECUENCIA DE IMAGENES CON HILOS 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;
//Debemos recordar que al trabajar con hilos debemos agregar la librería threading.
using System.Threading;
namespace films
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public string[] nomimages = new string[210];
        public int tamintervalo;

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtintervalo.Text == "")
            {
                MessageBox.Show("NECESITA INGRESAR UN INTERVALO \n PARA LOS FOTOGRAMAS!!!!!!");
            }
            else
            {
                tamintervalo = Convert.ToInt32(txtintervalo.Text);
                Thread th1 = new Thread(new ThreadStart(mostrar1));
                th1.Start();
                txtintervalo.Clear();
                txtintervalo.Focus();
            }
        }

        public void mostrar1()
        {
            for (int i = 0; i < nomimages.Length; i++)
            {
                pictureBox1.ImageLocation = nomimages[i];
                Thread.Sleep(tamintervalo);
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string nombre;
            for (int i = 0; i < nomimages.Length; i++)
            {
                nombre = i.ToString();
                //como mis imagenes fueron tomadas por una webcam me genera las imagenes
                //con el nombre Snapshot_20110307_+ el numero de imagen y agrego la extension .jpg para
                //que al ejecutar el programa las encuentre en la carpeta debug de mi proyecto
                nomimages[i] = "Snapshot_20110307_" + nombre + ".jpg";
            }
        }

        private void btncerrar_Click(object sender, EventArgs e)
        {
            progressBar1.Visible = true;
            progressBar2.Visible = true;
            progressBar1.Maximum = 1000000;
            progressBar1.Minimum = 0;
            progressBar1.Value = 0;
            progressBar1.Step = 50;
            progressBar2.Maximum = 1000000;
            progressBar2.Minimum = 0;
            progressBar2.Value = 0;
            progressBar2.Step = 50;
            for (int i = 0; i < progressBar1.Maximum; i = i + progressBar1.Step)
            {
                progressBar1.PerformStep();
                progressBar2.PerformStep();
            }
            this.Close();
        }

       
    }
}