[Lazarus] How many characters fit in a TEdit?
Bart
bartjunk64 at gmail.com
Mon Sep 30 18:45:14 CEST 2013
Hi,
Let me explain the subject of this topic.
Is it possible to determine how many characters fit in a TEdit (at
runtime), given that the choosen font is of fixed pitch (like
Courier).
Example:
TEdit: Width = 300
Font; Courier New, Size=16
TEdit.GetTextWidth() does not help here, it returns 16 for any font
and size (because we cannot access the canvas).
Why do I want to know this?
I have a TEdit.
It is readonly, and it cannot be reached by the cursor (intentionally).
When I have text in the control that is wider than the width of the
TEdit, the user can click on an arrow (or any other control that I
choose for that), and I then want to "scroll" the text in the control.
Say Text = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
Only the 'ABCDEFG' can be displayed in the TEdit.
I can "scroll" by setting SelStart, but to be able how many characters
I need to "scroll" each time, I need to know how many characters fit
into the TEdit in the first place (7 in this case).
I can sort of guess this at designtime, but at runtime fontsizes may
not be the same as on my machine...
Maybe I'm tackling the problem in the wrong way.
What I need is a control that can display text, it should not be
"editable" (you cannot put a cursor or caret in it (or at least it
should not show it)), the text should be right aligned, and if the
text is wider than the control, the text should be srollable by some
mechanisme.
Bart
More information about the Lazarus
mailing list