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
Starting a program with h...
by
jeremiah
[
Today
at 10:57:53 pm]
Q: Debug a plugin DLL - c...
by
d7_2_laz
[
Today
at 10:52:49 pm]
How make the GUI as one p...
by
Fibonacci
[
Today
at 10:49:16 pm]
Interesting article about...
by
440bx
[
Today
at 10:49:08 pm]
Classic objects — does FP...
by
Warfley
[
Today
at 10:46:49 pm]
SDL2 Fit image rotation b...
by
bobihot
[
Today
at 10:31:27 pm]
[Solved] Dumb SQLite ques...
by
heebiejeebies
[
Today
at 10:04:26 pm]
[Solved] Crosshair error ...
by
Marq01
[
Today
at 09:55:14 pm]
What is the history of di...
by
mika
[
Today
at 09:49:59 pm]
Unwanted additional line ...
by
Ten_Mile_Hike
[
Today
at 09:34:47 pm]
fpweb documentation do no...
by
Sniper
[
Today
at 09:02:16 pm]
Managed pointers
by
jksmithiii
[
Today
at 08:42:29 pm]
How to copy file to web
by
bobonwhidbey
[
Today
at 08:10:27 pm]
[Solved] Debug a plugin D...
by
d7_2_laz
[
Today
at 05:27:48 pm]
SAVE StringGrid to PDF
by
seghele0
[
Today
at 05:19:19 pm]
Who catches the Linux sig...
by
MarkMLl
[
Today
at 04:43:45 pm]
TvsComPort on MacOS Sierr...
by
Dzandaa
[
Today
at 04:23:21 pm]
Adding interfaces to any ...
by
Warfley
[
Today
at 03:48:44 pm]
Animated GIF's and Lazaru...
by
lainz
[
Today
at 03:11:11 pm]
[SOLVED] TRichMemo and te...
by
MarkMLl
[
Today
at 01:56:57 pm]
How to display empty stri...
by
krzynio
[
Today
at 01:55:38 pm]
crash db navigator with L...
by
calm_sea
[
Today
at 01:45:38 pm]
Common File Dialogs Have ...
by
zeljko
[
Today
at 01:05:36 pm]
Dymo label writers
by
MarkMLl
[
Today
at 11:25:25 am]
Application deployment
by
Warfley
[
Today
at 10:30:39 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: TMemo text width (Read 674 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: 12476
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