Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -856,27 +856,50 @@ protected virtual void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e)
return;
}

// Track images we allocate so they can be disposed after drawing.
Image? disabledImage = null;
Image? invertedImage = null;

if (e.Item is not null)
{
if (!e.Item.Enabled)
{
image = CreateDisabledImage(image, e.ImageAttributes);
disabledImage = CreateDisabledImage(image, e.ImageAttributes);
image = disabledImage;
}

if (SystemInformation.HighContrast && image is Bitmap bitmap)
if (image is Bitmap bitmap)
{
Color backgroundColor = e.Item.Selected ? SystemColors.Highlight : e.Item.BackColor;
if (SystemInformation.HighContrast)
{
Color backgroundColor = e.Item.Selected ? SystemColors.Highlight : e.Item.BackColor;

if (ControlPaint.IsDark(backgroundColor))
if (ControlPaint.IsDark(backgroundColor))
{
invertedImage = ControlPaint.CreateBitmapWithInvertedForeColor(bitmap, e.Item.BackColor);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To maintain logical consistency, the inversion here should use the same backgroundColor parameter as the conditional statement.

image = invertedImage;
}
}
else if (Application.IsDarkModeEnabled)
{
Image invertedImage = ControlPaint.CreateBitmapWithInvertedForeColor(bitmap, e.Item.BackColor);
image = invertedImage;
Color backgroundColor = e.Item.Selected ? SystemColors.Highlight : e.Item.BackColor;

if (ControlPaint.IsDark(backgroundColor))
{
// In dark mode, the check mark icons are dark glyphs designed for light
// backgrounds. Invert the foreground color so they are visible on dark backgrounds.
invertedImage = ControlPaint.CreateBitmapWithInvertedForeColor(bitmap, e.Item.BackColor);
image = invertedImage;
}
}
}
}

e.Graphics.DrawImage(image, imageRect, 0, 0, imageRect.Width,
imageRect.Height, GraphicsUnit.Pixel, e.ImageAttributes);

disabledImage?.Dispose();
invertedImage?.Dispose();
}

/// <summary>
Expand Down
Loading