Re: ListView column header text on column resizing?
- From: "Claes Bergefall" <claes.bergefall@xxxxxxxxxxxxx>
- Date: Tue, 15 Jan 2008 14:55:55 -0000
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
"Walter Sobchak" <walter@xxxxxxxxx> wrote in message
news:fmi69r$g28$1@xxxxxxxxxxxxxxxxxxx
This happens because I am using Graphics to draw the triangle after I
compute where to put it.
I'll try to do it that way.
I guess you are using your own and not system images?
Claes Bergefall wrote:
How are you putting the image in the column?
I tried my own control I've written and it doesn't experience the problem
you're describing. It uses an image list and with the standard properties
on the ColumnHeader class (i.e ImageIndex) the image ends up on the left
side of the text. In this case there obviously aren't any dots under the
image. Some tweaking with P/Invoke puts the image to the right of the
text, but the dots are still drawn to the left of the text. Not sure why
you get the dots drawn underneath the image.
Can you show a short sample to reproduce what you're seeing?
/claes
"Walter Sobchak" <walter@xxxxxxxxx> wrote in message
news:fmhqr0$euj$1@xxxxxxxxxxxxxxxxxxx
I have a listview control with a couple of columns. Sort order is
indicated with a litle triangle.
The problem is when the sorted column is resized to a smaller width the
text is shortened and there are 3 dots displayed at the end.
The dots are bellow the triangle so I'd like to delete the dots or make
the shortening of text happen earlier.
Thanks for any help.
p.s.
I tried cutting the text on columnwidthchanging event but it doesn't
alwasy work ok (sometimes when one char is left displayed the column
text variable is containing zero chars).
.
- Follow-Ups:
- Re: ListView column header text on column resizing?
- From: Walter Sobchak
- Re: ListView column header text on column resizing?
- References:
- ListView column header text on column resizing?
- From: Walter Sobchak
- Re: ListView column header text on column resizing?
- From: Claes Bergefall
- Re: ListView column header text on column resizing?
- From: Walter Sobchak
- ListView column header text on column resizing?
- Prev by Date: Re: Riddle Me This
- Next by Date: Re: Connect to unix server and execute a command
- Previous by thread: Re: ListView column header text on column resizing?
- Next by thread: Re: ListView column header text on column resizing?
- Index(es):
Relevant Pages
|