VintageRice

[Visual Studio] - batteryMonitor v2

Sep 11th, 2014
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.86 KB | None | 0 0
  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. namespace batteryMonitor_v2
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         int fadeTime = 500;
  16.        
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private void Form1_Load(object sender, EventArgs e)
  23.         {
  24.             ShowIcon = true;
  25.  
  26.             this.Left = Screen.PrimaryScreen.Bounds.Width - (this.Width + 10); //Awkward read-only bastard
  27.             this.Top = -(this.Height);
  28.         }
  29.  
  30.         private void fadeOut_Tick(object sender, EventArgs e)
  31.         {
  32.             if (fadeTime != 0)
  33.             {
  34.                 fadeTime--;
  35.             }
  36.             else
  37.             {
  38.                 fadeOut.Stop();
  39.                 outScroll.Start();
  40.  
  41.                 fadeTime = 500;                
  42.             }
  43.         }
  44.  
  45.         private void setGUI(string bottomLine, Color textColour)
  46.         {
  47.             label2.Text = bottomLine;
  48.             label2.SetBounds(((this.Width / 2) - (label2.Width / 2)), label2.Location.Y, label2.Width, label2.Height);
  49.  
  50.             foreach(Label L in this.Controls)
  51.             {
  52.                 ((Label)L).ForeColor = textColour;
  53.             }
  54.  
  55.             this.Show();
  56.             inScroll.Start();
  57.         }
  58.  
  59.         private void monitorPower_Tick(object sender, EventArgs e)
  60.         {
  61.             PowerLineStatus isCharging = SystemInformation.PowerStatus.PowerLineStatus;
  62.  
  63.             string tempPower = SystemInformation.PowerStatus.BatteryLifePercent.ToString("P0");
  64.             string getPower = tempPower.Replace("%", "");
  65.  
  66.             if(fadeOut.Enabled == false && this.Top <= -(this.Height))
  67.             {
  68.                 if (Convert.ToInt16(getPower) <= 15 && isCharging != PowerLineStatus.Online)
  69.                 {
  70.                     setGUI("Your battery needs charging!", Color.IndianRed);
  71.                 }
  72.  
  73.                 if (Convert.ToInt16(getPower) >= 100 && isCharging == PowerLineStatus.Online)
  74.                 {
  75.                     setGUI("Your battery is fully charged!", Color.ForestGreen);
  76.                 }
  77.             }
  78.         }
  79.  
  80.         private void inScroll_Tick(object sender, EventArgs e)
  81.         {
  82.             if (this.Top != 10)
  83.             {
  84.                 this.Top++;
  85.             }
  86.             else
  87.             {
  88.                 fadeOut.Start();
  89.                 inScroll.Stop();
  90.             }
  91.         }
  92.  
  93.         private void outScroll_Tick(object sender, EventArgs e)
  94.         {
  95.             if (this.Top != -(this.Height))
  96.             {
  97.                 this.Top--;
  98.             }
  99.             else
  100.             {
  101.                 outScroll.Stop();
  102.             }
  103.         }
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment