diff --git a/percentage/percentage/Program.cs b/percentage/percentage/Program.cs index 0e58ed0..0c5741e 100644 --- a/percentage/percentage/Program.cs +++ b/percentage/percentage/Program.cs @@ -11,6 +11,7 @@ static class Program [STAThread] static void Main() { + Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); diff --git a/percentage/percentage/TrayIcon.cs b/percentage/percentage/TrayIcon.cs index d3643c6..aa5dd8e 100644 --- a/percentage/percentage/TrayIcon.cs +++ b/percentage/percentage/TrayIcon.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.Drawing; +using System.Management; using System.Runtime.InteropServices; using System.Windows.Forms; @@ -47,16 +49,40 @@ private void timer_Tick(object sender, EventArgs e) { PowerStatus powerStatus = SystemInformation.PowerStatus; batteryPercentage = (powerStatus.BatteryLifePercent * 100).ToString(); + bool charging = SystemInformation.PowerStatus.BatteryChargeStatus.HasFlag(BatteryChargeStatus.Charging); - using (Bitmap bitmap = new Bitmap(DrawText(batteryPercentage, new Font(iconFont, iconFontSize), Color.White, Color.Black))) + Color fontColor; + if (charging) + { + fontColor = Color.FromArgb(255, 0, 255, 0); + } + else + { + fontColor = Color.FromArgb(255, 255, 255, 255); + + } + + using (Bitmap bitmap = new Bitmap(DrawText(batteryPercentage, new Font(iconFont, iconFontSize), fontColor, Color.FromArgb(0, 0, 0, 0)))) { System.IntPtr intPtr = bitmap.GetHicon(); try { using (Icon icon = Icon.FromHandle(intPtr)) { - notifyIcon.Icon = icon; + notifyIcon.Icon = icon; notifyIcon.Text = batteryPercentage + "%"; + if (!charging) + { + int seconds = SystemInformation.PowerStatus.BatteryLifeRemaining; + int mins = seconds / 60; + int hours = mins / 60; + mins = mins % 60; + notifyIcon.Text += "\n" + " " + hours + ":" + mins + " remaining"; + } + else + { + notifyIcon.Text = "Charging"; + } } } finally @@ -85,7 +111,7 @@ private Image DrawText(String text, Font font, Color textColor, Color backColor) // create a brush for the text using (Brush textBrush = new SolidBrush(textColor)) { - graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; + graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; graphics.DrawString(text, font, textBrush, 0, 0); graphics.Save(); }