TextRenderer problem

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
 
S

Stuart Nathan

The problem I had was that the ListView got re-written.
The only way around this was to write my own listview.
 
X

Xafier

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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top