How to truncate a long directory path (Views: 710)
Problem/Question/Abstract: I want to draw a directory path on a canvas, but then I have a fixed width for the canvas. So I would like to truncate long directory names to fit in the canvas like "C:\Directory1\Directory2\Directory3\Directory4\Aaahhh\Finally" should be truncated to "C:\...\Aaahhh\Finally" or "C:\...\Finally" depending on width available. Answer: procedure DrawPath(ACanvas: TCanvas; const Path: string; Rect: TRect); begin DrawText(ACanvas.Handle, PChar(Path), -1, Rect, DT_PATH_ELLIPSIS); end; |