カスタム チェックリスト ボックスを作成して、特定の項目の前景色を変更できるようにしましたが、MutiColumn を有効にすると、複数の列で作業するのではなく、値が互いに重なってしまいます。
public sealed class CustomCheckedListBox : CheckedListBox
{
public CustomCheckedListBox()
{
DoubleBuffered = true;
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
Size checkSize = CheckBoxRenderer.GetGlyphSize(e.Graphics,
System.Windows.Forms.VisualStyles.CheckBoxState.MixedNormal);
int dx = (e.Bounds.Height - checkSize.Width)/2;
e.DrawBackground();
bool isChecked = GetItemChecked(e.Index); //For some reason e.State doesn't work so we have to do this instead.
CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(dx, e.Bounds.Top + dx),
isChecked
? System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal
: System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal);
using (StringFormat sf = new StringFormat {LineAlignment = StringAlignment.Center})
{
using (Brush brush = new SolidBrush(isChecked ? CheckedItemColor : BackColor))
{
e.Graphics.DrawString(Items[e.Index].ToString(), Font, brush,
new Rectangle(e.Bounds.Height, e.Bounds.Top, e.Bounds.Width - e.Bounds.Height, e.Bounds.Height), sf);
}
}
}
private Color _checkedItemColor = Color.Blue;
public Color CheckedItemColor
{
get { return _checkedItemColor; }
set
{
_checkedItemColor = value;
Invalidate();
}
}
}
これが起こらないようにするために必要な変更を誰かが提案できますか?