Mirror

How to remove the scrollbar of a TListBox (Views: 706)


Problem/Question/Abstract:

I want to remove the scrollbar of a TListBox and control scrolling with a separate scrollbar. Anyone has an idea how to remove it?

Answer:

This requires a somewhat dubious hack. Derive a new component from TListBox, like this:


type
  TNoVScrolllistbox = class(TListBox)
  private
    procedure WMNCCalcSize(var msg: TMessage); message WM_NCCALCSIZE;
  end;

procedure TNoVScrolllistbox.WMNCCalcSize(var msg: TMessage);
var
  style: Integer;
begin
  style := GetWindowLong(handle, GWL_STYLE);
  if (style and WS_VSCROLL) <> 0 then
    SetWindowLong(handle, GWL_STYLE, style and not WS_VSCROLL);
  inherited;
end;


This technique works for nearly any control that uses the standard window scrollbars.

<< Back to main page