Important alert: (current site time 7/16/2013 5:50:22 AM EDT)
 

article

Add a horizontal scrollbar to a listbox

Email
Submitted on: 8/5/2000 11:56:06 PM
By: Bryan Hammond  
Level: Intermediate
User Rating: By 1 Users
Compatibility: Delphi 5, Delphi 4
Views: 19644
 
     This code will add a horizontal scrollbar to a standard TListBox component using win32 api.

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				procedure TForm1.Timer1Timer(Sender: TObject);
var
i,len,width: integer;
begin
  with listbox1 do
  begin
  width := 0;
  for i := 0 to items.count -1 do
  begin
  len := canvas.textwidth(items[i]);
  if len > width then width := len;
  end;
  //set listbox's horizontal scrollbar width
  Perform(LB_SETHORIZONTALEXTENT,width+100,0);
  end;
end;
 


Other 3 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
10/11/2000 3:02:20 AMNicky Sciberras

I think that the variable 'width' should be changed to something else (eg width1) as it is effecting the listbox's width as it is.
(If this comment was disrespectful, please report it.)

 
4/10/2002 11:49:02 AMsamar

its really help ful for me as i am beginer in delphi
so
(If this comment was disrespectful, please report it.)

 
5/10/2002 3:22:06 AMPetr Langer

boxlen := listbox.Perform(LB_GETHORIZONTALEXTENT, 0, 0) can also be useful for getting scrollbar size.
(If this comment was disrespectful, please report it.)

 
7/23/2004 1:46:23 PMChe Guevara

procedure TForm1.Timer1Timer(Sender: TObject);
var
i, len, width1: integer;
begin
with lstDir do
begin
width1 := 0;
for i := 0 to items.count -1 do
begin
len := canvas.textwidth(items[i]);
if len > width1 then width1 := len;
end;
Perform(LB_SETHORIZONTALEXTENT,width1+100,0);
end;
end;
//I renamed the var width to width1 other wise the listboxes width will interfear with the variable.
(If this comment was disrespectful, please report it.)

 
7/23/2004 1:48:43 PMChe Guevara

add:
I wreckon that this code would be better off on the listboxes OnChange event than a timer.
(If this comment was disrespectful, please report it.)

 
1/21/2005 8:06:22 PMShane Mc Cormack

But there is no OnChange event for TListBox
(If this comment was disrespectful, please report it.)

 
8/9/2005 7:57:49 AMNgnhuman

It'll be better if you change procedure TTime1.Time by procedure Form1.FormCreate
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.