Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Change font color with light/dark mode #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion percentage/percentage/TrayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Microsoft.Win32;

namespace percentage
{
Expand Down Expand Up @@ -74,7 +75,18 @@ private void TimerTick(object sender, EventArgs e)
String percentage = (powerStatus.BatteryLifePercent * 100).ToString();
bool isCharging = SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online;
String bitmapText = isCharging ? percentage + "*" : percentage;
using (Bitmap bitmap = new Bitmap(GetTextBitmap(bitmapText, new Font(font, fontSize), Color.White)))
Color bitmapColor;
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize");
if (key != null)
{
bitmapColor = (int)key.GetValue("SystemUsesLightTheme") == 0 ? Color.White : Color.Black;
key.Close();
}
else
{
bitmapColor = Color.White;
}
using (Bitmap bitmap = new Bitmap(GetTextBitmap(bitmapText, new Font(font, fontSize), bitmapColor)))
{
System.IntPtr intPtr = bitmap.GetHicon();
try
Expand Down