Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Free Pascal
»
Beginners
(Moderators:
FPK
,
Tomas Hajny
) »
TMemo text width
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
YM Player
by
TRon
[
Today
at 02:32:16 am]
How single procedure ends...
by
Marion
[
Today
at 01:57:43 am]
Python4Lazarus Undefined ...
by
Grew
[
Today
at 01:57:41 am]
ct2laz - convertor betwee...
by
Sharfik
[
Today
at 01:26:03 am]
StringGrid colored rows d...
by
wp
[December 02, 2024, 11:21:00 pm]
Amigo programming languag...
by
maurog
[December 02, 2024, 11:19:44 pm]
[SOLVED] How to document ...
by
korba812
[December 02, 2024, 10:49:39 pm]
AVRPascal – free code edi...
by
ackarwow
[December 02, 2024, 10:18:22 pm]
storing string
by
Remy Lebeau
[December 02, 2024, 09:46:56 pm]
How do you know wich vers...
by
Warfley
[December 02, 2024, 08:32:11 pm]
Unable to find file "date...
by
Cumberland
[December 02, 2024, 08:27:29 pm]
Common File Dialogs Have ...
by
rvk
[December 02, 2024, 07:33:14 pm]
Developing a Kernel Modul...
by
nicolap
[December 02, 2024, 05:37:05 pm]
LazMapView - adding a sca...
by
alpine
[December 02, 2024, 05:26:28 pm]
[SOLVED] Howto use a DEFI...
by
tintinux
[December 02, 2024, 04:55:13 pm]
ZDataset.Locate + loParti...
by
tintinux
[December 02, 2024, 04:47:48 pm]
Strange memory allocation...
by
MathMan
[December 02, 2024, 03:40:40 pm]
Best UI to adopte while d...
by
marcov
[December 02, 2024, 02:42:45 pm]
Random SnowFlakes:
by
Boleeman
[December 02, 2024, 12:24:18 pm]
AY_FLY Library
by
Thaddy
[December 02, 2024, 11:50:21 am]
Hustle - A simple task ma...
by
MarkMLl
[December 02, 2024, 11:37:20 am]
How much would it hamper ...
by
Thaddy
[December 02, 2024, 11:36:24 am]
Lazarus MDI application.
by
Fred vS
[December 02, 2024, 11:25:21 am]
Linking question
by
Khrys
[December 02, 2024, 10:23:13 am]
CudaText Editor (written ...
by
AlexTP
[December 02, 2024, 10:16:27 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: TMemo text width (Read 670 times)
Kaller
Jr. Member
Posts: 73
TMemo text width
«
on:
September 28, 2023, 11:42:01 am »
TMemo does not seem to expose a canvas property, I want to calculate the text width of a Memo line given font etc. I was thinking maybe I need a temporary canvas or something just to do the calculation. What's the best way to go about it?
Logged
wp
Hero Member
Posts: 12457
Re: TMemo text width
«
Reply #1 on:
September 28, 2023, 12:50:05 pm »
You could temporatily create a bitmap, or a TControlCanvas for the control under investigation:
Code: Pascal
[Select]
[+]
[-]
function
GetControlTextWidth
(
AControl
:
TControl
;
AText
:
String
)
:
Integer
;
var
c
:
TControlCanvas
;
begin
c
:
=
TControlCanvas
.
Create
;
try
c
.
Control
:
=
AControl
;
c
.
Font
.
Assign
(
AControl
.
Font
)
;
Result
:
=
c
.
TextWidth
(
AText
)
;
finally
c
.
Free
;
end
;
end
;
procedure
TForm1
.
Button1Click
(
Sender
:
TObject
)
;
var
w
:
Integer
;
begin
w
:
=
GetControlTextWidth
(
Memo1
,
'Memo1'
)
;
ShowMessage
(
w
.
ToString
)
;
end
;
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Free Pascal
»
Beginners
(Moderators:
FPK
,
Tomas Hajny
) »
TMemo text width
TinyPortal
© 2005-2018