Note that there are some explanatory texts on larger screens.

plurals
  1. POWord-wrapping in a rectangle, while allowing words to be truncated
    primarykey
    data
    text
    <p>I'm making a scheduling application which looks similar to Google Calendar, iCalendar, Outlook's calendar, and similar... As you may have seen in such apps, scheduled events are represented in rectangles, which can be very small especially if you're viewing a whole week.</p> <p>My challenge is to give the user a "meaningful summary" of the event before they click it, using text in the rectangle. The text should be very compact. To that end, I want it to wrap lines in a way that isn't very common, but I suspect .NET is capable of handling it natively.</p> <p>If a single word is wider than the rectangle, only the beginning of that word should show. But wrapping should still occur upon encountering spaces, if the word which follows would fall partly outside the rectangle. Not every space will cause wrapping to the next line, because if two or more words happen to fit on a line that's fine.</p> <p>I suspect that the answer lies in the capabilities of StringFormat, StringTrimming, and FormatFlags, but I haven't found the right combination to accomplish the goals.</p> <p>For example if we have...</p> <pre><code>Chuck Norris Dentist Appointment </code></pre> <p>Due to limited space it might become...</p> <pre><code>Chuc Norr Denti Appo </code></pre> <p>I do NOT want it to become:</p> <pre><code>Chuc k Norr is Dent ist Appo intme nt </code></pre> <p>As you see in this example, if the user already knows who Chuck Norris is, the presence of letter "k" and the letters "is" don't help the user recognize the name. In fact, the presence of those letters may force "Dentist Appointment" to be hidden from view because vertical space is also limited.</p> <p>I already know how to draw text in a rectangle that wraps in the normal way, and I also know how to get it to avoid drawing any text that falls outside the rectangle. What I DON'T know is how to get it to wrap upon encountering a space (or carriage return) while preventing it from wrapping mid-word if a single word is wider than the rectangle. Any help there?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload