Yes, I draw my own images and put them in an imagelist. Then assign the
imagelist to the ListView.SmallImageList
There doesn't seem to be a .NET way to right align the image though, so
you'll have to use some P/Invoke
1. Use LVM_GETHEADER to get a handle to the column header control
2. Use HDM_SETITEM to set a new format flag (the fmt member in the HDITEM
structure)) that includes HDF_BITMAP_ON_RIGHT
You should only need to do this once upon startup
Here's the code I use to create the image list with the arrows in it. It's
in VB.NET though, but should be easy to understand:
Private Function CreateSortingImages() As ImageList
Dim imgList As New ImageList
Dim imgUpArrow As New Bitmap(16, 16,
Drawing.Imaging.PixelFormat.Format32bppArgb)
Dim imgDownArrow As New Bitmap(16, 16,
Drawing.Imaging.PixelFormat.Format32bppArgb)
imgList.ImageSize = New Size(16, 16)
imgList.ColorDepth = ColorDepth.Depth8Bit
imgList.TransparentColor = SystemColors.Desktop
Dim penLeft As New Pen(SystemColors.ControlDark, 1)
Dim penRight As New Pen(SystemColors.ControlLightLight, 1)
Dim brushBackground As New SolidBrush(SystemColors.Control)
Dim brushTransparent As New SolidBrush(SystemColors.Desktop)
Dim dc As Graphics
Dim point1 As Point
Dim point2 As Point
Dim point3 As Point
Dim point4 As Point
Dim point5 As Point
Dim point6 As Point
' Up arrow image - Index 0
dc = Graphics.FromImage(imgUpArrow)
dc.FillRectangle(brushTransparent, 0, 0, 16, 16)
point1 = New Point(7, 5)
point2 = New Point(8, 5)
point3 = New Point(11, 10)
point4 = New Point(11, 11)
point5 = New Point(4, 11)
point6 = New Point(4, 10)
dc.FillPolygon(brushBackground, New Point() {point1, point2, point3,
point4, point5, point6})
dc.DrawLine(penLeft, point6, point1)
dc.DrawLine(penRight, point2, point3)
dc.DrawLine(penRight, point4, point5)
imgList.Images.Add(imgUpArrow, SystemColors.Desktop)
' Down arrow image - Index 1
dc = Graphics.FromImage(imgDownArrow)
dc.FillRectangle(brushTransparent, 0, 0, 16, 16)
point1 = New Point(4, 4)
point2 = New Point(11, 4)
point3 = New Point(11, 5)
point4 = New Point(8, 10)
point5 = New Point(7, 10)
point6 = New Point(4, 5)
dc.FillPolygon(brushBackground, New Point() {point1, point2, point3,
point4, point5, point6})
dc.DrawLine(penLeft, point1, point2)
dc.DrawLine(penRight, point2, point4)
dc.DrawLine(penLeft, point5, point6)
imgList.Images.Add(imgDownArrow, SystemColors.Desktop)
Return imgList
End Function
/claes