How do I align text for a single subitem in a ListView using C#?

后端 未结 6 1021
离开以前
离开以前 2021-01-18 08:57

I wasn\'t able to find an answer anywhere about this seemingly simple topic: is it possible to align text of a single subitem in a WinForms ListView control?

6条回答
  •  孤独总比滥情好
    2021-01-18 09:38

    Building on the answer by @Fueled, here's what I did to use the column header alignment:

        protected override void OnDrawSubItem( DrawListViewSubItemEventArgs e )
            {
            // Match the subitem alignment to the column header alignment
            TextFormatFlags flags = TextFormatFlags.Left;
            switch ( this.Columns[ e.ColumnIndex ].TextAlign )
                {
                case HorizontalAlignment.Right:
                    flags = TextFormatFlags.Right;
                    break;
                case HorizontalAlignment.Center:
                    flags = TextFormatFlags.HorizontalCenter;
                    break;
                }
            e.DrawText( flags );
            }
    

提交回复
热议问题