Is there a succinct way of accessing the canvas of a hint window? I don't want to draw anything on the canvas - I will just assign to the component's Hint
property - but I do want to find out the width of text that Windows would render using whatever font is being used for the hint window text.
* The Reason *
I'm trying to construct hint windows with tabbed columns in them, e.g.
SomeControl.Hint :=
'Item 1: ' + #9 + 'Tom' + #13 +
'Item 2: ' + #9 + 'Dick' + #13 +
'Another Item: ' + #9 + 'Harry' + #13 ;
and I want the names to all tab under one another. The example shown above will tab correctly only if the hint font is mono-spaced. I can achieve it with a given proportional font by trial and error by padding the lines with the right number of spaces, but I want it to work for any font. Most of the examples I have seen seem to be for changing the appearance of the hint window - all I want to do is be able to call Canvas.TextWidth
so I can calculate what padding I need to add to "push" the line over the next tab stop.
* UPDATE *
I was labouring under a misapprehension - I was assuming that the hint control respected the tab character but in fact it seems to ignore it. The TLabel component on the other hand does respect the tab character - it seems to move to the next multiple of 10 or so space widths.
There are two ways to achieve what you want.
Screen.HintFont
property than you can assign to any canvas you want and get your hint text dimensions.HintWindowClass
Delphi application uses to create hint windows and you can create your own and use its canvas to do text measuring.You can use it like this:
var
HintCtrl: THintWindow;
HintCtrl := HintWindowClass.Create(nil);
HintCtrl.Canvas.TextWidth('abc');
...