Ver Mensaje Individual
  #4  
Antiguo 01-03-2019
REHome REHome is offline
Miembro
 
Registrado: jul 2003
Ubicación: España
Posts: 454
Reputación: 21
REHome Va por buen camino
Buenas:

Ya lo he conseguido. Dejo el código por si alguien lo necesita o le pica la curiosidad.


Código C#:
Código:
using System;
using System.Threading;

namespace Barra_progreso_consola_03_cs
{
    class Program
    {
        // Variable.
        static double resultadoPorcentaje;

        static void Main(string[] args)
        {
            Console.Title = "Simulador barra de progreso";
            Console.WindowWidth = 60;   // X ancho.
            Console.WindowHeight = 10;  // Y altura.
            Console.CursorVisible = false;

            // Variable.
            int barra = 58;
            int porcentaje = 0;

            // Dibujamos la barra del portentaje.
            Console.SetCursorPosition(0, 3);
            Console.Write("0 %                         50 %                       100 %");
            Console.SetCursorPosition(0, 4);
            Console.Write("┌────────────────────────────┬───────────────────────────┐");
            Console.SetCursorPosition(0, 5);
            Console.Write("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); // Ascii 176.
            Console.SetCursorPosition(0, 5);
            Console.ForegroundColor = ConsoleColor.Yellow;

            for (int i = 0; i < barra; i++)
            {
                resultadoPorcentaje = (i + 1.0D) / (barra / 100.0);

                Console.Write("█"); // Muestra ASCII 219 Dec y DB en Hex.
                                    // Console.Write((char)219);
                                    // Console.Write(Encoding.ASCII.GetBytes((char)219));
                porcentaje++; // Incrementa valor.

                PintarCargando(porcentaje);

                Thread.Sleep(300); // 100 ms o 0.1 segundos.
            }

            // Pulse cualquier tecla para salir.
            Console.ReadKey();
        }      

        static void PintarCargando(int porcentaje)
        {
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.SetCursorPosition(0, 1);
            Console.Write("Cargado: " + (resultadoPorcentaje).ToString("N0") + " %");// por dos para que simule el 100%

            // Reestablecemos para que vuelva a pintar bajo la línea de carga.
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.SetCursorPosition(porcentaje, 5);
        }
    }
}
Saluditos gente.
__________________
http://electronica-pic.blogspot.com....n-arduino.html Manuales de electrónica general, PIC y Arduino.
Responder Con Cita