title: How to add a dynamically changing float value to a label
body: <p>I'm coding this app that pulls your battery % and shows it to the user periodically. I've made it work so far as a console app, but as I re-write it in Windows Forms it gives me some issues when using the labels to display the value. </p>
  
  <p><em>Edit: I have included the changes Niranjan Kala pointed out as I was using more than one label for this, but it still doesn't work</em></p>
  
  <p><em>Also, as he has requested, I have added more of the program layout so as to provide some context and maybe find the error</em></p>
  
  <p>This is what it looks like:</p>
  
  <pre><code>public partial class Form1 : Form 
  { 
  
  public Form1() 
  
  { InitializeComponent(); 
  
  // Imagine all the visual stuff going here (icons and menus, etc.)
  
  //I start the thread
  batThing = new Thread(new ThreadStart(batThing)); 
  batThing.Start();
   }
  
  
   private void Form1_Load(object sender, EventArgs e)
      {
          Type power = typeof(PowerStatus);
          PropertyInfo[] pi = power.GetProperties();
  
  
              #region Cargador
  
  
          //0 = PowerLineStatus --&gt; Charger on or not?
          object EdeCargador = pi[0].GetValue(SystemInformation.PowerStatus, null);
  
          //turns charger state into int
          int edc = Convert.ToInt32(EdeCargador);
  
          int On = Convert.ToInt32(PowerLineStatus.Online);
          On = 1;
          int Off = Convert.ToInt32(PowerLineStatus.Offline);
          Off = 0;
          int Unk = Convert.ToInt32(PowerLineStatus.Unknown);
          Unk = 255;
  
          if (edc == On)
          {
              string CargadorConectado = "-Cargador Conectado-";
              label2.Text = CargadorConectado;
              string EdeBateria2 = "-Cargando-";
              label4.Text = EdeBateria2;
          }
          else
          {
              string CargadorDesconectado = "-Cargador Desconectado-";
              label2.Text = CargadorDesconectado;
              #endregion
  
              #region Cantidad de Bateria
  
              //3 = BatteryLifePercent --&gt; tells the % of bat available
              object CantdeBat = pi[3].GetValue(SystemInformation.PowerStatus, null);
  
              //string to float , then * 100 to get a %
              float num = (Single.Parse(CantdeBat.ToString())) * 100;
  
              // shows a % and says if battery is full or low
              string EdeBateria = num.ToString() + "%";
  
              if (num == 100)
              {
                  EdeBateria = "-Batería Completa-";
                  label4.Text = EdeBateria;
              }
              else if (num &lt;= 25)
              {
                  EdeBateria = "-Batería Baja. Conecte el cargador-";
                  label4.Text = EdeBateria;
  
              }
              else if (num &gt; 25 &amp; num &lt; 100)
              {
                  //nada
              }
  
              if (num &lt;= 0)
              {
                  EdeBateria = "No tenes bateria gil";
                  label4.Text = EdeBateria;
              }
  
  
  
          }
          #endregion
  
          #region Tiempo Restante
          //4 = BatteryLifeRemaining --&gt; Indicates the remaining battery time
          object TdeBat = pi[4].GetValue(SystemInformation.PowerStatus, null);
  
              double tiempobat = (Double.Parse(TdeBat.ToString()));
  
              if (tiempobat == -1)
              {
                  string NoHayBat = "El equipo no está operando a través de una batería";
                  label5.Text = NoHayBat;
              }
              else if (tiempobat != -1)
              {
                  //gets time in seconds and turns it into hours , min and secs
                  TimeSpan t = TimeSpan.FromSeconds(tiempobat);
                  string TiempoRestante = string.Format("El tiempo de uso restante es de: {0:D1} horas, {1:D2} minutos y {2:D2} segundos",
                   t.Hours,
                   t.Minutes,
                   t.Seconds
                   );
  
                  label5.Text = TiempoRestante ;
  
  
              }
              #endregion
  
      } // fin de form1
  </code></pre>
  
  <p><em>Edit: I have found that there are certain issues when jumping from one method from another, for instance, the problem I originally had, which was with 'label 4' I came to find that was due to the logic in the charger state, so I added this:</em></p>
  
  <pre><code>  string EdeBateria2 = "-Cargando-";
              label4.Text = EdeBateria2;
  </code></pre>
  
  <p>After adding this when I have the charger connected it displays so nicely, but when I disconnect the charger entering the 'else' where I coded the conditionals for label 4 the problems begin.</p>
  
  <p>The strings in both label 2 and label 5 change dinamically as I disconnect the charger out of the laptop PC with no problems whatsoever, the issue is with label 4 still. As I disconnect the charger it stops displaying the message I define as '-Cargando-' and it just shows its name 'label4'.</p>
  
  <p>I'm stuck, any ideas?</p>
  
  <p>I'm using C# in VS 2015.</p>