[Lazarus] Measuring text width in a TEdit
Martin Frb
lazarus at mfriebe.de
Tue May 30 14:12:21 CEST 2017
On 30/05/2017 07:36, Torsten Bonde Christiansen via Lazarus wrote:
> Hi List.
>
> I want to know the placement of the caret (in pixels, not character
> count) in a TEdit. However i am struggeling to fint a method that will
> allow me to do so.
>
> If i try to calculate it using the assigned font, I have the problem
> that TEdit.Font.GetTextWidth always returns the default size (16),
> since the Font doesn't have a canvas assigned to it.
If you are on windows (and win only), you may be able to use GetCaretPos
https://msdn.microsoft.com/en-us/library/windows/desktop/ms648402(v=vs.85).aspx
(That is, if the edit is focused, and has the caret)
On Windows there is only one caret per App, so if the TEdit has it, then
GetCaretPos should get the pos for that Edit.
Of course win only, and the Edit needs the focus. (And not tested at all)
More information about the Lazarus
mailing list