2010. június 11., péntek

How to determine if a TListBox has a scrollbar


Problem/Question/Abstract:

I'm trying to ensure that a TListBox is wide enough to hold the items in it. However, I see no method for determining if a scroll bar exists, and if so how wide it is.

Answer:

procedure TForm1.FormShow(Sender: TObject);
var
  LBStyle: Longint;
begin
  LBStyle := GetWindowLong(ListBox1.Handle, GWL_STYLE);
  if (LBStyle and WS_VSCROLL) <> 0 then
    ShowMessage(' ScrollBar visible, its width is ' + IntToStr(GetSystemMetrics(SM_CYVSCROLL))
      + ' pixels ')
  else
    ShowMessage('ScrollBar not visible');
end;

Nincsenek megjegyzések:

Megjegyzés küldése