views:

853

answers:

2

Useing Winform and VB.Net - how can I change the column header height?

+1  A: 

Windows does allow you to change the height of the column headers, and it does allow you to change the font for the headers -- BUT it is far from easy. It's Windows, what do you expect? :)

To do either of these things, you have to delve into the world of Windows control and messages.

To change the height, you have to deal with the HDM_LAYOUT message from Windows. This message is sent to the header control. In that message, you can control the bounds of the header control and the bounds of the list. Similarly, to change the font, you need to intercept the NM_CUSTOMDRAW notification, and set the font for the device context.

There are several complications here: .NET doesn't expose the header control; NM_CUSTOMDRAW has several stages and you must release resources appropriately.

But, if you are using VB.NET, you can avoid all trouble and just use ObjectListView (an open source wrapper around .NET WinForms ListView). That can change the header height and allows different fonts and colors on each column, if you want. Even if you don't use the control, you can just read the source to see how it's done.

This example shows different fonts, colors, and word wrapping in action:

alt text

Grammarian
A: 

It has nothing to do with the font. You need to subclass the ListView's header control and process the HDM_LAYOUT message. I wrote a simple demo of the technique: http://www.codeproject.com/KB/list/VHHListView.aspx

dlchambers