Hi @DaveF , Welcome to Microsoft Q&A,
I removed the lines that set the CompositingQuality and SmoothingMode and changed the font in the DrawString method to the font in the event parameter. This should ensure that text drawn in the ListBox is anti-aliased.
private void LbColorPalette_DrawItem(object sender, DrawItemEventArgs e)
{
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
e.DrawBackground();
if (e.Index < 0 || e.Index >= m_colorPalette.Count)
{
return;
}
var color = m_colorPalette[e.Index];
var swatchSize = e.Bounds.Height - 10;
e.Graphics.FillRectangle(new SolidBrush(color), e.Bounds.X + 4, e.Bounds.Y + 4, swatchSize, swatchSize);
e.Graphics.DrawRectangle(new Pen(Color.Black), e.Bounds.X + 4, e.Bounds.Y + 4, swatchSize, swatchSize);
var text = color.GetColorName();
var textOriginX = e.Bounds.X + swatchSize + 10;
var textOriginY = e.Bounds.Y + ((e.Bounds.Height - e.Font.Height) / 2);
e.Graphics.DrawString(text, e.Font,
new SolidBrush(((e.State & DrawItemState.Selected) == DrawItemState.Selected) ? Color.White : Color.Black),
textOriginX, textOriginY);
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.