Foros del Web » Programación para mayores de 30 ;) » .NET »

Añadir porcentaje al progressBar

Estas en el tema de Añadir porcentaje al progressBar en el foro de .NET en Foros del Web. Hola: Estoy haciendo una pequeña prueba. Recibo en el puerto serie / USB datos que recoge Visual C# de 0 a 1023 y lo muestro ...
  #1 (permalink)  
Antiguo 27/02/2016, 06:42
 
Fecha de Ingreso: mayo-2007
Ubicación: PIC-16F84A
Mensajes: 727
Antigüedad: 16 años, 10 meses
Puntos: 8
Añadir porcentaje al progressBar

Hola:

Estoy haciendo una pequeña prueba. Recibo en el puerto serie / USB datos que recoge Visual C# de 0 a 1023 y lo muestro en un label.



Hasta ahí funciona bien.

Tengo dos label más. El segundo tiene que demostrar el porcentaje del 0 % a 100% según el dato obtenido del 0 a 1023.

En el otro label, el tercero debemostrar número con decimales del 0.00 a 5.00.

A pesar de encontrar la fórmula, no se implementarlo en C#.

El código es este:
Código C++:
Ver original
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. using System.IO.Ports; // No olvidar.
  12.  
  13. namespace Arduino_In_Analogico_prueba_01
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         // Utilizaremos un string como buffer de recepción.
  18.         string Recibidos;
  19.         int Porcentaje;
  20.  
  21.         public Form1()
  22.         {
  23.             InitializeComponent();
  24.  
  25.             if (!serialPort1.IsOpen)
  26.             {
  27.                 try
  28.                 {
  29.                     serialPort1.Open();
  30.                 }
  31.                 catch (System.Exception ex)
  32.                 {
  33.                     MessageBox.Show(ex.ToString());
  34.                 }
  35.             }
  36.  
  37.             serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
  38.         }
  39.  
  40.         // Al recibir datos.
  41.         private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
  42.         {
  43.  
  44.             // Acumula los caracteres recibidos a nuestro 'buffer' (string).
  45.             Recibidos = serialPort1.ReadLine();
  46.  
  47.             // Invocar o llamar al proceso de tramas.
  48.             Invoke(new EventHandler(Actualizar));
  49.         }
  50.  
  51.  
  52.         // Como variables de clase
  53.  
  54.         private string[] separador = new string[] { ",", "\r", "\n", "/n" };
  55.         private List<string> leodato1 = new List<string>();
  56.  
  57.        
  58.        
  59.         // Procesar los datos recibidos en el bufer y extraer tramas completas.
  60.         private void Actualizar(object sender, EventArgs e)
  61.         {
  62.             // En el evento
  63.             leodato1.Clear();
  64.             leodato1.AddRange(Recibidos.Split(separador,StringSplitOptions.RemoveEmptyEntries));
  65.  
  66.             label_Lectura_Potenciometro.Text = leodato1[0].ToString();
  67.             progressBar1.Value = Convert.ToInt32(leodato1[0].ToString());
  68.             progressBar1.PerformStep();
  69.         }
  70.     }
  71. }

Saludos.
__________________
Meta Shell, VERSIÓN 1.2.2
Descargar
  #2 (permalink)  
Antiguo 17/03/2016, 16:46
Avatar de cortess_13  
Fecha de Ingreso: abril-2015
Ubicación: Tijuana
Mensajes: 14
Antigüedad: 9 años
Puntos: 0
Respuesta: Añadir porcentaje al progressBar

Estas utilizando un timer para llevar el conteo ???
  #3 (permalink)  
Antiguo 17/03/2016, 22:23
 
Fecha de Ingreso: mayo-2007
Ubicación: PIC-16F84A
Mensajes: 727
Antigüedad: 16 años, 10 meses
Puntos: 8
Respuesta: Añadir porcentaje al progressBar

Ya me salió.

Código C++:
Ver original
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. using System.IO.Ports; // No olvidar.
  12.  
  13. namespace Arduino_In_Analogico_prueba_01
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         // Utilizaremos un string como buffer de recepción.
  18.         string Recibidos;
  19.  
  20.         public Form1()
  21.         {
  22.             InitializeComponent();
  23.  
  24.             if (!serialPort1.IsOpen)
  25.             {
  26.                 try
  27.                 {
  28.                     serialPort1.Open();
  29.                 }
  30.                 catch (System.Exception ex)
  31.                 {
  32.                     MessageBox.Show(ex.ToString());
  33.                 }
  34.             }
  35.  
  36.             serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
  37.         }
  38.  
  39.         // Al recibir datos.
  40.         private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
  41.         {
  42.  
  43.             // Acumula los caracteres recibidos a nuestro 'buffer' (string).
  44.             Recibidos = serialPort1.ReadLine();
  45.  
  46.             // Invocar o llamar al proceso de tramas.
  47.             Invoke(new EventHandler(Actualizar));
  48.         }
  49.  
  50.  
  51.         // Como variables de clase
  52.         private string[] Separador = new string[] { ",", "\r", "\n", "/n" };
  53.         private List<string> Leo_Dato1 = new List<string>();
  54.  
  55.         // Procesar los datos recibidos en el bufer y extraer tramas completas.
  56.         private void Actualizar(object sender, EventArgs e)
  57.         {
  58.             double Voltaje = 0;
  59.             double Porcentaje = 0;
  60.  
  61.             // En el evento
  62.             Leo_Dato1.Clear();
  63.             Leo_Dato1.AddRange(Recibidos.Split(Separador, StringSplitOptions.RemoveEmptyEntries));
  64.  
  65.             label_Lectura_Potenciometro.Text = Leo_Dato1[0].ToString();
  66.             progressBar1.Value = Convert.ToInt32(Leo_Dato1[0].ToString());
  67.  
  68.             double Dato_Voltaje = Convert.ToDouble(Leo_Dato1[0]);
  69.             double Dato_Porcentaje = Convert.ToDouble(Leo_Dato1[0]);
  70.            
  71.             Voltaje = Dato_Voltaje * (5.00 / 1023.00);
  72.             Porcentaje = Dato_Porcentaje * (100.00 / 1023.00);
  73.  
  74.             label_Voltio.Text = Voltaje.ToString("N2") + " V.";
  75.             label_Portentaje.Text = Porcentaje.ToString("N0") + " %";
  76.            
  77.  
  78.         }
  79.     }
  80. }
__________________
Meta Shell, VERSIÓN 1.2.2
Descargar

Etiquetas: porcentaje, progressbar
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:12.