Fixed tray progress indicator to be DPI-aware

This commit is contained in:
SupSuper 2018-06-08 18:13:14 +01:00
parent d8008f993c
commit dbba4fbb1a

View file

@ -574,24 +574,25 @@ public static Icon GetProgressIcon(int percentage)
{
percentage = percentage.Between(0, 99);
using (Bitmap bmp = new Bitmap(16, 16))
Size size = SystemInformation.SmallIconSize;
using (Bitmap bmp = new Bitmap(size.Width, size.Height))
using (Graphics g = Graphics.FromImage(bmp))
{
int y = (int)(16 * (percentage / 100f));
int y = (int)(size.Height * (percentage / 100f));
if (y > 0)
{
using (Brush brush = new SolidBrush(Color.FromArgb(16, 116, 193)))
{
g.FillRectangle(brush, 0, 15 - y, 16, y);
g.FillRectangle(brush, 0, size.Height - 1 - y, size.Width, y);
}
}
using (Font font = new Font("Arial", 12, GraphicsUnit.Pixel))
using (Font font = new Font("Arial", 10))
using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
{
g.DrawString(percentage.ToString(), font, Brushes.Black, 8, 8, sf);
g.DrawString(percentage.ToString(), font, Brushes.White, 8, 7, sf);
g.DrawString(percentage.ToString(), font, Brushes.Black, size.Width / 2, size.Height / 2, sf);
g.DrawString(percentage.ToString(), font, Brushes.White, size.Width / 2, size.Height / 2 - 1, sf);
}
return Icon.FromHandle(bmp.GetHicon());