MeasureString Compact Framework

D

Dan Ardelean

Hy,

Compact framework supports only:
public SizeF MeasureString(string, Font);
but not:
public SizeF MeasureString(string, Font, int);

where I give the maximum width and it returns the SizeF
structure with information about the heigth. Any ideas of
how can I implement (simulate) the second method?? Why do
I need it? I generate a listbox with text items from
database and I don't want the horizontal bar to appear and
the largest text to be visible (to set the height so the
largest text is visible). I look at the article on
OpenNETCF abut owner draw list and the height is set
statically to 2 lines if wrapttext property is set and the
text is too long. Does anyone knows which is the algorithm
for word wrap. Does this can be done in another way? (to
set the heigth of the items in a list so the largest text
in the list is visible entirely and without horizontal
bar)!

Hope I explained myself!


Thanks!

Best regards,
Dan
 
S

Steven

I don't know if someone has a better answer, but I just
loop backwards within the string (or forwards, depending
on the situation) until I find a string that fits.
 
B

Brian

Hi Steven,

Could you explain your approach to looping through the string?

I am trying to do something similar, starting by using the
Text.split(vbCRLF) function to get an array of
potentially-word-wrapped strings and count hard carriage returns.
Then I am using measureString() on each one to determine how many
lines each may have. I'm always off by a few characters.

Thanks,
Brian
 

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

Top