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
TCalendar View disconnect...
by
TRon
[
Today
at 06:25:54 am]
Lazarus Release Candidate...
by
calebs
[
Today
at 04:00:47 am]
How C++ class multiple in...
by
TYDQ
[
Today
at 03:23:05 am]
Compile on multiple distr...
by
Handoko
[
Today
at 03:17:29 am]
Preparing FPC 3.2.4, poin...
by
Fred vS
[
Today
at 03:16:53 am]
My first "tool" written w...
by
TRon
[
Today
at 03:15:48 am]
Memory Safety and Object ...
by
440bx
[
Today
at 03:06:08 am]
Status of GLScene for Laz...
by
TRon
[
Today
at 02:47:39 am]
Resolving procedure symbo...
by
TRon
[
Today
at 01:33:03 am]
How do you maintain your ...
by
dbannon
[
Today
at 01:23:24 am]
UK's Online Safety Act
by
Joanna from IRC
[
Today
at 01:08:32 am]
Run ffmpeg via TProcess
by
TRon
[
Today
at 01:07:59 am]
Minor Q: HowTo use 'Debug...
by
Martin_fr
[January 21, 2025, 11:41:36 pm]
Time & Billing Accounting...
by
silvercoder70
[January 21, 2025, 11:17:33 pm]
D2Bridge Framework for La...
by
nummer8
[January 21, 2025, 09:38:44 pm]
IContainers
by
cdbc
[January 21, 2025, 07:28:18 pm]
fpc trunk:I can't build i...
by
zoltanleo
[January 21, 2025, 07:09:08 pm]
Loading TIFF Files in Bgr...
by
wp
[January 21, 2025, 05:51:54 pm]
Does not suggest function...
by
WooBean
[January 21, 2025, 05:40:56 pm]
[SOLVED] using TForm.OnPa...
by
Remy Lebeau
[January 21, 2025, 05:34:54 pm]
No access to the wiki
by
Thaddy
[January 21, 2025, 04:55:31 pm]
Error 403 downloading wit...
by
Thaddy
[January 21, 2025, 03:29:23 pm]
Select cell in listview /...
by
Jonny
[January 21, 2025, 02:32:19 pm]
Post your artwork made fr...
by
circular
[January 21, 2025, 12:41:24 pm]
[SOLVED] SetPart ?
by
circular
[January 21, 2025, 12:28:21 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: TMemo text width (Read 714 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: 12525
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