The function CompactPath can be used to compact a path for being displayed on a Graphics object with a specific font:
Catching the exception is a very costly operation, returning a Boolean variable that indicates the success of the operation would be the better approach when calling the method several times.
If the compacted path string is not needed, there is a managed alternative to the code shown above that can be used to draw the compacted path to a Graphics object. The listing below contains a skeleton of an implementation for a label control displaying a compacted path. In order to use this control in a real-world application, objects need to be disposed and some other properties need to be taken into account when drawing the text. Basing the control on System.Windows.Forms.Label would be possible too: