jueves, 31 de octubre de 2019

Ejemplo Progress bar

Requisitos:

  • Sistema Operativo: Windows 
  • IDE: Visual Studio 2009, framework 4.0 


Paso 1: Diseño interfaz



NOTA: como se ve en la captura se agregado en componente “Timer”.



Paso 2: Código.
   
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 Ejemplo_Progress_bar
{
    public partial class Principal : Form
    {
        public Principal()
        {
            InitializeComponent();
        }

        private void butLanzar_Click(object sender, EventArgs e)
        {
            // Reset
            progressBar1.Value = 0;
            progressBar1.Maximum = int.Parse(txtTiempo.Text);

            // Activamos el Timer
            timer1.Interval = 1000; // 1 Segundo
            timer1.Start();
        }

        // Evento del timer
        private void timer1_Tick(object sender, EventArgs e)
        {
            // Comparamos si se ha llegado al limite
            if (progressBar1.Maximum == progressBar1.Value)
            {
                timer1.Stop();
                MessageBox.Show("Completado");
            }

            // Avanzamos el la barra
            progressBar1.Increment(1);
        }
    }
}


Resultado:

No hay comentarios:

Publicar un comentario