Setting custom tabstops in a ListBox.

Question:

How can I set custom tab stops in a TListbox control?

Answer:

You will need to send a LB_SETTABSTOPS message to the Listbox.

Note: The Listbox tabwidth property must be set to a number other than zero for the LB_SETTABSTOPS mesage to work.

Example:

procedure TForm1.FormCreate(Sender: TObject);

begin

  ListBox1.TabWidth := 1;

  ListBox1.Items.Add('one'+#9+'one');

  ListBox1.Items.Add('two'+#9+'two');

  ListBox1.Items.Add('three'+#9+'three');

end;

 

procedure TForm1.Button1Click(Sender: TObject);

var

  DialogUnitsX : LongInt;

  PixelsX : LongInt;

  i : integer;

  TabArray : array[0..4] of integer;

begin

  DialogUnitsX := LoWord(GetDialogBaseUnits);

  PixelsX := SpinEdit1.Value;

  for i := 1 to 5 do begin

  TabArray[i - 1] :=

  ((PixelsX * i ) * 4) div DialogUnitsX;

  end;

  if SendMessage(ListBox1.Handle,

  LB_SETTABSTOPS,

  5,

  LongInt(@TabArray)) = 0 then

  ShowMessage('Tabs Not Set');

  Listbox1.Refresh;

end;