是否可能制作一个列出一堆自定义控件的列表框?我想你可能需要调用某些子对象的自定义绘制,但我不知道如何做到这一点。有人可以解释一下吗?
是否可能制作一个列出一堆自定义控件的列表框?我想你可能需要调用某些子对象的自定义绘制,但我不知道如何做到这一点。有人可以解释一下吗?
private void OnDrawItem(object sender, DrawItemEventArgs e)
{
Rectangle rect = e.Bounds;
rect.Offset(0, -rect.Top);
using (Bitmap bitmap = new Bitmap(rect.Width, rect.Height))
{
Control control = (Control)listBox.Items[e.Index];
control.DrawToBitmap(bitmap, rect);
rect = e.Bounds;
e.Graphics.DrawImage(bitmap, e.Bounds);
}
}
使用WPF很容易做到这一点,只需使用基本组合。在WinForms世界中,您可能需要将容器设为自定义控件。