Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
LCL
»
List box item height
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
IRC channel
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
Find child controls by na...
by
Handoko
[
Today
at 04:17:05 am]
Demoscene The Champs Crac...
by
Gigatron
[
Today
at 02:26:07 am]
Linux Workspaces -- StayO...
by
dbannon
[
Today
at 02:13:13 am]
Assign (textfile) not com...
by
teresa
[
Today
at 01:56:13 am]
How to: create DLL file f...
by
KodeZwerg
[
Today
at 12:57:56 am]
Slow copying of small str...
by
jamie
[
Today
at 12:37:04 am]
location of non visual co...
by
VisualLab
[April 17, 2024, 11:58:55 pm]
For-in loop over constant...
by
Joanna
[April 17, 2024, 11:57:15 pm]
Lazarus editor feature re...
by
440bx
[April 17, 2024, 11:49:08 pm]
InstallAware Using Lazaru...
by
VisualLab
[April 17, 2024, 11:08:24 pm]
How would you define a fi...
by
wp
[April 17, 2024, 11:04:00 pm]
Directx9 with mylogo insi...
by
KodeZwerg
[April 17, 2024, 11:03:54 pm]
Lazarus for Windows on aa...
by
Wallaby
[April 17, 2024, 10:25:46 pm]
Azure sql database will n...
by
dseligo
[April 17, 2024, 10:15:27 pm]
[SOLVED] TDbf table, Leve...
by
1HuntnMan
[April 17, 2024, 10:03:16 pm]
Doomed name
by
Martin_fr
[April 17, 2024, 09:09:52 pm]
lazarus-project_3.2.0-0_a...
by
midigark
[April 17, 2024, 06:09:40 pm]
Text orientation in TMemo...
by
wp
[April 17, 2024, 05:51:25 pm]
TBGRABitmap.TextSize retu...
by
circular
[April 17, 2024, 05:24:04 pm]
BUG REPORT: Unable to gen...
by
gasensor
[April 17, 2024, 05:10:20 pm]
[solved]FP IDE(FP.exe) fa...
by
gasensor
[April 17, 2024, 04:45:40 pm]
Inherits forms and releas...
by
ASerge
[April 17, 2024, 03:37:45 pm]
The weird Rewrite bug
by
Kays
[April 17, 2024, 01:23:40 pm]
FpDebug unexpected Assemb...
by
440bx
[April 17, 2024, 12:54:43 pm]
Arabic text, problem on L...
by
Zaher
[April 17, 2024, 12:34:05 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: List box item height (Read 700 times)
tailkinker
Newbie
Posts: 6
List box item height
«
on:
June 14, 2022, 12:37:18 pm »
So the TListbox.ItemHeight documentation states that this is not implemented. How can I determine the height of each item in the TListBox? (I want to make the TListBox automatically scale with items, so I never need to worry about scroll bars.)
Logged
wp
Hero Member
Posts: 11915
Re: List box item height
«
Reply #1 on:
June 14, 2022, 01:05:12 pm »
Set the Style to lbOwnerDrawFixed, and you can set ItemHeight to any value. Or set Style to lbOwnerDrawVariable, and you can define an individual height for each line by implementing a handler for the OnMeasureItem event.
Logged
tailkinker
Newbie
Posts: 6
Re: List box item height
«
Reply #2 on:
June 14, 2022, 01:17:58 pm »
The problem is that I want to determine the height as set by the font being used, rather than trying to guess. (Which is what I am currently doing.)
Logged
wp
Hero Member
Posts: 11915
Re: List box item height
«
Reply #3 on:
June 14, 2022, 01:50:13 pm »
The following code yields the same line height as that of a listbox with lbStandard style. --> Just measure the height of some text in the listbox (you could use the Listbox.canvas directly, but since that is not always available I used an auxiliary bitmap):
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
FormCreate
(
Sender
:
TObject
)
;
var
bmp
:
TBitmap
;
h
:
Integer
;
begin
bmp
:
=
TBitmap
.
Create
;
try
bmp
.
SetSize
(
1
,
1
)
;
bmp
.
Canvas
.
Font
:
=
Listbox2
.
Font
;
h
:
=
bmp
.
Canvas
.
TextHeight
(
'Tg'
)
;
finally
bmp
.
Free
;
end
;
Listbox2
.
ItemHeight
:
=
h
;
end
;
Logged
tailkinker
Newbie
Posts: 6
Re: List box item height
«
Reply #4 on:
June 14, 2022, 02:06:42 pm »
Unfortunately, this does not work. The size returned does not in fact equal the height in pixels of the text when displayed in the listbox.
Logged
wp
Hero Member
Posts: 11915
Re: List box item height
«
Reply #5 on:
June 14, 2022, 02:53:53 pm »
I am on Windows, and the code is working (see also the attached project). But since the listbox is controlled by the widgetset this may not be true for other operating systems. Just run the attached demo and adjust the "extra pixels" (added to the pure "char height") so that the line heights of both listboxes are the same (the left one has Style lbStandard).
Logged
tailkinker
Newbie
Posts: 6
Re: List box item height
«
Reply #6 on:
June 14, 2022, 05:48:38 pm »
Well, that works, but it means mucking with the source every time I change environments. I think I'll look at using a different control. Thanks to all those that helped.
Logged
wp
Hero Member
Posts: 11915
Re: List box item height
«
Reply #7 on:
June 14, 2022, 07:18:18 pm »
Ah, there's a simpler way: Query the rectangle occupied by an item:
Code: Pascal
[Select]
[+]
[-]
var
R
:
TRect
;
...
R
:
=
AListbox
.
ItemRect
(
0
)
;
height
:
=
R
.
Bottom
-
R
.
Top
;
«
Last Edit: June 14, 2022, 07:21:52 pm by wp
»
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
LCL
»
List box item height
TinyPortal
© 2005-2018