在.NET4 WinForm的列表视图多行的列标题视图、标题、列表、WinForm

2023-09-04 22:42:03 作者:盐焗小星球

我在详细信息视图中的ListView和我已经添加列。我想有列标题高度增加,要么自动换行头文本或允许我使用CRLF指定换行符。

I have a listview in Details view and I have added columns. I would like to have the column header increase in height and either word-wrap the header text or allow me to specify the line break using a CrLf.

这可能使用标准的.NET控件?

Is this possible using the standard .NET controls?

推荐答案

这是困难的,你不能直接控制的列标题的高度。您可以通过给ListView的大字体做到这一点间接。然后,您需要设置OwnerDraw属性为true,并落实DRAWITEM,DrawSubItem和DrawColumnHeader事件。后者可以让你的文字换行。您还需要添加,因此不画大以及字体属性为每个ListViewItem的设置。不愉快的,但并非不可能。

That's difficult, you cannot control the column header height directly. You can do it indirectly by giving the ListView a big Font. You then need to set the OwnerDraw property to true and implement the DrawItem, DrawSubItem and DrawColumnHeader events. The latter lets you word-wrap the text. You will also need to set the Font property for each ListViewItem you add so they are not drawn large as well. Unpleasant but not impossible.