[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Delphi - count visible lines on TListBox

Posted on 2011-02-23
5
Medium Priority
?
1,425 Views
Last Modified: 2012-06-27
How can I count how much lines are visible in the same time on specific listbox. The user have the ability to change the font size, so I need to know how many lines are visible in any font size.
0
Comment
Question by:oferlll
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 19

Expert Comment

by:Thommy
ID: 34960117
Try this...
function TListBox.VisibleLines: Integer;
begin
  Result := Height div (Abs(Self.Font.Height) + 2);
end;

Open in new window

0
 
LVL 8

Expert Comment

by:BdLm
ID: 34960128
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


function ListBoxItemsVisible( aListBox : TListBox ) : Integer;
begin

     result := round (aListBox.ClientHeight /  aListBox.ItemHeight) ;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
       edit1.Text := IntToStr( ListBoxItemsVisible(ListBox1));
end;

end
0
 
LVL 24

Accepted Solution

by:
jimyX earned 2000 total points
ID: 34960138
You can divide the ListBox.Height over the ListBox.ItemHeight.
You can write the following code in a Button onclick event:
Showmessage(IntToStr(ListBox1.Height Div ListBox1.ItemHeight));

Open in new window

0
 
LVL 19

Expert Comment

by:Thommy
ID: 34960154
Demo project...
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
    function VisibleLines(AListBox:TListBox): Integer;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.VisibleLines(AListBox:TListBox): Integer;
begin
  Result := AListBox.Height div (Abs(AListBox.Font.Height) + 2);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(inttostr(VisibleLines(ListBox1)));
end;

end.

Open in new window

0
 
LVL 8

Expert Comment

by:BdLm
ID: 34960164
a bit spice it up:

function ListBoxItemsVisible( aListBox : TListBox ) : Integer;
var    MaxItems   : Integer ;
begin

     MaxItems := aListBox.Items.Count;

     result := round (aListBox.ClientHeight /  aListBox.ItemHeight) ;

     
     if result > MaxItems then result := MaxItems;   //  if ListBox not full, report the count of items inside the box


end;
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question