简体   繁体   中英

How do I position the Image from the ListView at the left from the column?

Problem :
I've got a ListView with an Image in the first column. But the problem is that the Image isn't positioned at the left but weird in the center, so that you can't see the full username.
Question :
So is there a way to position the image at the left, so that you can see the username correctly?
Code :
The Code that adds the 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);
        }

Screenshot

Here you can try two ways, One

listView1.Columns["columnName"].TextAlign = HorizontalAlignment.Left;

or you can use event DrawSubItem in this way

private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
    TextFormatFlags flags = TextFormatFlags.Left;
    if (e.ColumnIndex == 0)
    {
        flags = TextFormatFlags.Right;
    }

    e.DrawText(flags);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM