C# Change ListView Item's/Row's height

前端 未结 6 1399
轻奢々
轻奢々 2020-12-08 20:43

I want to change the Item\'s/Row\'s height in listview.

I searched every where and I figured that in order to change the height I need to use LBS_OWNERDRAWFIXE

6条回答
  •  粉色の甜心
    2020-12-08 21:02

    The default line height of a ListView (in report view mode) is computed based on the control's font size.

    So to select the line height, choose a font with the right height in the ListView properties. For example, select MS Sans Serif 18.

    Then you can change the font used by all items: when you insert a new item, set its font property.

    To optimize font assignment you should declare the item font as a private member of the form:

    Private Font stdfont = new Font( "Consolas", 9.0f, FontStyle.Regular );
    

    Then when adding items :

    ListViewItem i = new ListViewItem( "some text" );
    i.Font = stdfont;
    MyListView.Items.Add( i );
    

    This trick is the only easy one allowing to have SMALLER line height ;) i.E. set control's font size to 7 and set items' font size to 10. (Tested with VS 2008 )

提交回复
热议问题