Ver Mensaje Individual
  #3 (permalink)  
Antiguo 17/03/2016, 22:23
REHome
 
Fecha de Ingreso: mayo-2007
Ubicación: PIC-16F84A
Mensajes: 727
Antigüedad: 17 años
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