Hello everybody!
I have an odd problem with an enhanced WinForms ComboBox I wrote in C#. The box shows a list of colors with the color itself and the name of the color and is set to ComboBoxStyle.DropDownList, double buffering and DrawMode.OwnerDrawFixed. The items are drawn when the DrawItem-event is raised.
If I open the DropDown menu and scroll with the mouse wheel the behaviour and look and feel is alright. If I use the scrollbar thumb with the left mouse button the text in the panel gets all smudgy. Only if I hover over the shown items again the items will be redrawn correctly.
Help is much appreciated!
Michael
Edit: Code of the drawing method:
private void OnDrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index == -1)
{
return;
}
e.DrawBackground();
Graphics grfx = e.Graphics;
grfx.FillRectangle(mWhiteBrush, e.Bounds);
ColorInfo colorInfo = (ColorInfo)Items[e.Index];
Color brushColor = colorInfo.Color;
using (SolidBrush brush = new SolidBrush(brushColor))
{
Rectangle rectangleColor = e.Bounds;
Rectangle rectangleText = e.Bounds;
rectangleColor.Width = rectangleColor.Height;
rectangleText.X += rectangleColor.Width;
rectangleText.Width -= rectangleColor.Width;
grfx.FillRectangle(brush, rectangleColor);
grfx.DrawString(colorInfo.Name, e.Font, mBlackBrush, rectangleText);
}
}