并非不可能,但非常困难。您的建议不起作用,请注意类 CheckedListBox 中方法 DrawItem 的元数据:
// Summary:
// Occurs when a visual aspect of an owner-drawn System.Windows.Forms.CheckedListBox
// changes. This event is not relevant to this class.
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public event DrawItemEventHandler DrawItem;
因此,您唯一的选择是从CheckedListBox 派生您自己的类,在我有限的测试中,这将是一条漫长的道路。您可以简单地处理绘图,如下所示:
public class CustomCheckedListBox : CheckedListBox
{
protected override void OnDrawItem(DrawItemEventArgs e)
{
String s = Items[e.Index].ToString();
s += "APPEND"; //do what you like to the text
CheckBoxState state = GetCheckBoxState(e.State); // <---problem
Size glyphSize = CheckBoxRenderer.GetGlyphSize(e.Graphics, state);
CheckBoxRenderer.DrawCheckBox(
e.Graphics,
e.Bounds.Location,
new Rectangle(
new Point(e.Bounds.X + glyphSize.Width, e.Bounds.Y),
new Size(e.Bounds.Width - glyphSize.Width, e.Bounds.Height)),
s,
this.Font,
false,
state);
}
}
注意方法GetCheckBoxState()。你在DrawItemEventArgs 中得到的是DrawItemState,而不是你需要的CheckBoxState,所以你必须翻译,这就是我开始走下坡路的地方。
士兵,如果你愿意,这应该可以让你开始。但我认为这将是一条混乱而漫长的道路。