[英]How do I position the Image from the ListView at the left from the column?
问题:
我在第一列中有一个带有图像的 ListView。 但问题是图像不是位于左侧,而是位于中心位置很奇怪,因此您看不到完整的用户名。
问题:
那么有没有办法把左边的图片改成position,这样就可以正确看到用户名了?
代码:
添加 ListViewItem 的代码
public void AddMessage(string from, string message)
{
ListViewItem item = new ListViewItem(new string[] {from, DateTime.Now.GetDateTimeFormats()[7], message});
item.ImageIndex = 0;
listView1.Items.Add(item);
}
在这里你可以尝试两种方法,一种
listView1.Columns["columnName"].TextAlign = HorizontalAlignment.Left;
或者您可以通过这种方式使用事件DrawSubItem
private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
TextFormatFlags flags = TextFormatFlags.Left;
if (e.ColumnIndex == 0)
{
flags = TextFormatFlags.Right;
}
e.DrawText(flags);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.