TextRenderer problem

  • Thread starter Thread starter Xafier
  • Start date Start date
X

Xafier

Hi,

I'm creating a control that overrides ListView and so I'm working on
redrawing everything myself with some changes here and there...

But I'm having a problem with drawing the text inside the rectangle on
LargeIcon mode... I thought I'd finally discovered the solution with
TextRenderer but this still doesn't give the correct results.

Here's the code I'm trying to use (item is a ListViewItem)

Rectangle text_rect = item.GetBounds(ItemBoundsPortion.Label);

TextFormatFlags formatFlags = TextFormatFlags.WordBreak |
TextFormatFlags.HorizontalCenter | TextFormatFlags.Top |
TextFormatFlags.EndEllipsis;

if (item.Text != null && item.Text.Length > 0)
TextRenderer.DrawText(dc, item.Text, item.Font, text_rect,
item.ForeColor, item.BackColor, formatFlags);

The problem is that its still not exactly what the original ListView
displays... ie

I'm displaying:
___________
| some |
| really long |

original ListView displays:
___________
| some really |
| long text |

Surely it should fit inside the bounding box if its using the GDI draw
method and I'm using the bounding box thats returned to me from the
ListViewItem itself? Any ideas?

thanks
Kris Wragg
 
The problem I had was that the ListView got re-written.
The only way around this was to write my own listview.
 
I believe I have found the answer to my problem... using the flag:

TextFormatFlags.NoPadding

seems to give me exactly the same text layout, I'm only using this if
its the LargeIcon layout, hopefully sometime this afternoon I will have
a nice flicker free ListView base class with a few extra tweaks :)
 
Back
Top