我正在制作一个所有者绘制的列表视图,其中我在列表视图中绘制形状。我已经使用Listview_DrawItem
事件做到了这一点。我的问题是,当我运行应用程序时,我无法选择在列表视图中绘制的形状。
private void AddItem(ListView lvw, string Shape_name, Color Shape_color)
{
// Make the item.
ListViewItem item = new ListViewItem(Shape_name);
// Save the Shape object in the Tag property.
Shapes myShape = new Shapes(Shape_name,Shape_color);
item.Tag = myShape;
item.SubItems[0].Name ="ShapeName";
// Add subitems so they can draw.
item.SubItems.Add("ShapeColor");
// Add the item to the ListView.
lvw.Items.Add(item);
}
// Draw the item. In this case, the Shape_name's logo.
private void lvwServers_DrawItem(object sender, DrawListViewItemEventArgs e)
{
// Get the ListView item and the Shapes object.
ListViewItem item = e.Item;
Shapes myShape = item.Tag as Shapes;
// Clear.
e.DrawBackground();
// Smoothing mode for blur free drawing
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
Rectangle rect = new Rectangle(e.Bounds.Left + 10, e.Bounds.Top + 10, 41, 41);
using (SolidBrush br = new SolidBrush(myShape.ShapeColor))
{
e.Graphics.FillRectangle(br, rect);
}
e.Graphics.DrawRectangle(Pens.Black, rect);
e.Graphics.ResetTransform();
e.DrawFocusRectangle();
另外,我无法更改e.bound
属性值。