ListView中没有项目的行缩进 [英] No row indentation for items in ListView
本文介绍了ListView中没有项目的行缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在开发某些软件,客户对特定的UI更改感到僵硬,这给我带来了一些麻烦:
I'm currently working on some software and the customer is dead-set on a specific UI change that has been giving me some trouble:
我希望ListView中的项目没有缩进.为了说明,我更改了ListView和项目的背景色.
I would like items in a ListView to not have any indentation. To illustrate I changed the backcolor of the ListView and the items.
现在,每个项目左侧的小块也应该是白色的.有什么想法吗?
Now, the little piece to the left of each item should also be white. Any ideas?
推荐答案
You can set the OwnerDraw
property of ListView
to true
and using DrawItem
, DrawColumnHeader
and DrawSubItem
draw the list view yourself.
例如:
private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e)
{
e.Graphics.DrawString(e.Item.Text, e.Item.Font, Brushes.Black,
new Rectangle(e.Bounds.Left-2, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height));
}
private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
e.DrawDefault = true;
}
private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
if(e.ColumnIndex>0)
e.DrawDefault = true;
}
注意:
- 上面的呈现只是一个示例,它向您展示了如何在所需位置绘制项目文本,例如使用的
ListView
控件的rel ="nofollow">OwnerDraw
属性.
- The above rendering is just an example and shows you how you can draw item text in desired location for example using using
Graphics.DrawString
. - Also it shows you how to set
e.DrawDefault = true;
to perform default rendering. - The first subitem of each ListViewItem object represents the parent item itself
- To avoid issues with graphics flickering when owner drawing, override the
ListView
control and set theDoubleBuffered
property to true. - To learn more, read documents of
OwnerDraw
property ofListView
control.
这篇关于ListView中没有项目的行缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文