C# ListView drawsubitem-未选择列
为什么没有选择第4列?我使用listView3\u DrawSubItem和e.DrawDefault=true;对于该列,现在不可选择 编辑: listView1\u子项代码:C# ListView drawsubitem-未选择列,c#,winforms,listview,C#,Winforms,Listview,为什么没有选择第4列?我使用listView3\u DrawSubItem和e.DrawDefault=true;对于该列,现在不可选择 编辑: listView1\u子项代码: // Only interested in 2nd column. if (e.Header != this.action) { e.DrawDefault = true; return; }
// Only interested in 2nd column.
if (e.Header != this.action)
{
e.DrawDefault = true;
return;
}
drawItem(e);
以及drawitem代码:
string drawString = e.SubItem.Text;
float size = 8.25F;
e.DrawBackground();
Bitmap image = new Bitmap(DesktopCleaner.Properties.Resources.folder_icon_512x512);
if (drawString == "Leave on Desktop")
{
image = new Bitmap(DesktopCleaner.Properties.Resources.desk);
}
else if (drawString == "Recycle")
{
image = new Bitmap(DesktopCleaner.Properties.Resources.recyclebin_preview_1);
}
else if (drawString == "Delete")
{
image = new Bitmap(DesktopCleaner.Properties.Resources.free_vector_delete_icon_101805_Delete_icon);
}
var imageRect = new Rectangle(e.Bounds.X + 3, e.Bounds.Y, image.Width - 2, image.Height - 2);
e.Graphics.DrawImage(image, imageRect);
System.Drawing.Font drawFont = new System.Drawing.Font(listView1.Font.FontFamily, size, FontStyle.Bold);
System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat();
var strrect = new Rectangle(e.Bounds.X + 18, e.Bounds.Y + 3, 150, e.Bounds.Height);
e.Graphics.DrawString(drawString, drawFont, drawBrush, strrect, drawFormat);
您负责绘制所选内容 因此,即使你使用了一些不错的方法:
e.DrawBackground();
e.DrawText();
未绘制任何选择
因此,您需要使用FillRectangle
和DrawString
以及适当的颜色,可能如下所示:
bool selected = e.Item.Selected;
using ( SolidBrush backBrush = new SolidBrush(
selected? SystemColors.MenuHighlight :SystemColors.Window ) )
e.Graphics.FillRectangle(backBrush, e.Bounds);
using (SolidBrush textBrush = new SolidBrush(
selected ? Color.White : Color.Black ))
e.Graphics.DrawString(e.Item.Text, yourFont, textBrush, e.Bounds.X, e.Bounds.Y);
代码简化;您将使用坐标为图标等腾出空间。您负责绘制选择
因此,即使你使用了一些不错的方法:
e.DrawBackground();
e.DrawText();
未绘制任何选择
因此,您需要使用FillRectangle
和DrawString
以及适当的颜色,可能如下所示:
bool selected = e.Item.Selected;
using ( SolidBrush backBrush = new SolidBrush(
selected? SystemColors.MenuHighlight :SystemColors.Window ) )
e.Graphics.FillRectangle(backBrush, e.Bounds);
using (SolidBrush textBrush = new SolidBrush(
selected ? Color.White : Color.Black ))
e.Graphics.DrawString(e.Item.Text, yourFont, textBrush, e.Bounds.X, e.Bounds.Y);
代码简化;您将使用坐标为图标等腾出空间。您负责绘制选择
因此,即使你使用了一些不错的方法:
e.DrawBackground();
e.DrawText();
未绘制任何选择
因此,您需要使用FillRectangle
和DrawString
以及适当的颜色,可能如下所示:
bool selected = e.Item.Selected;
using ( SolidBrush backBrush = new SolidBrush(
selected? SystemColors.MenuHighlight :SystemColors.Window ) )
e.Graphics.FillRectangle(backBrush, e.Bounds);
using (SolidBrush textBrush = new SolidBrush(
selected ? Color.White : Color.Black ))
e.Graphics.DrawString(e.Item.Text, yourFont, textBrush, e.Bounds.X, e.Bounds.Y);
代码简化;您将使用坐标为图标等腾出空间。您负责绘制选择
因此,即使你使用了一些不错的方法:
e.DrawBackground();
e.DrawText();
未绘制任何选择
因此,您需要使用FillRectangle
和DrawString
以及适当的颜色,可能如下所示:
bool selected = e.Item.Selected;
using ( SolidBrush backBrush = new SolidBrush(
selected? SystemColors.MenuHighlight :SystemColors.Window ) )
e.Graphics.FillRectangle(backBrush, e.Bounds);
using (SolidBrush textBrush = new SolidBrush(
selected ? Color.White : Color.Black ))
e.Graphics.DrawString(e.Item.Text, yourFont, textBrush, e.Bounds.X, e.Bounds.Y);
代码简化;您将使用坐标为图标等腾出空间。它可能已被选中,但不会显示。如何绘制选择?当您有e.DrawDefault=true
时,图标从何而来?你能给我们看看DrawSubItem
code吗?我刚刚更新了问题。你忽略了e.ItemState。不,不明白。我应该在何处使用e.ItemState?如我所见,如果我选择所有项目或一个部分,然后右键单击,从上下文菜单中选择某个内容,它将只影响焦点行。我如何为所有人创造?它可能已被选中,但未显示。如何绘制选择?当您有e.DrawDefault=true
时,图标从何而来?你能给我们看看DrawSubItem
code吗?我刚刚更新了问题。你忽略了e.ItemState。不,不明白。我应该在何处使用e.ItemState?如我所见,如果我选择所有项目或一个部分,然后右键单击,从上下文菜单中选择某个内容,它将只影响焦点行。我如何为所有人创造?它可能已被选中,但未显示。如何绘制选择?当您有e.DrawDefault=true
时,图标从何而来?你能给我们看看DrawSubItem
code吗?我刚刚更新了问题。你忽略了e.ItemState。不,不明白。我应该在何处使用e.ItemState?如我所见,如果我选择所有项目或一个部分,然后右键单击,从上下文菜单中选择某个内容,它将只影响焦点行。我如何为所有人创造?它可能已被选中,但未显示。如何绘制选择?当您有e.DrawDefault=true
时,图标从何而来?你能给我们看看DrawSubItem
code吗?我刚刚更新了问题。你忽略了e.ItemState。不,不明白。我应该在何处使用e.ItemState?如我所见,如果我选择所有项目或一个部分,然后右键单击,从上下文菜单中选择某个内容,它将只影响焦点行。我能为大家做些什么?