Recent

Author Topic: [Solved] ListBox OnMeasureItem call it OnResize  (Read 4323 times)

lainz

  • Hero Member
  • *****
  • Posts: 4473
    • https://lainz.github.io/
[Solved] ListBox OnMeasureItem call it OnResize
« on: February 25, 2017, 12:36:01 am »
Hi, ListBox configured as lbOwnerDrawVariable can handle different item heights. However when I resize the form the items are not resized, and it's a common problem, like you can read here

https://social.msdn.microsoft.com/Forums/Windows/en-US/0dce187f-a5b7-47d9-8a3c-6fe4b5e40c6d/listbox-ownerdrawvariable-itemheight-not-set-on-resize?forum=winformsdesigner

In that post there's a solution but for C#.

Any ideas on how I can force internal OnMeasureItem call to resize each item?

Attached all the source code.
« Last Edit: February 25, 2017, 12:24:06 pm by lainz »

esvignolo

  • Full Member
  • ***
  • Posts: 159
  • Using FPC in Windows, Linux, Macos
Re: ListBox OnMeasureItem call it OnResize
« Reply #1 on: February 25, 2017, 05:59:34 am »
Hi Lainz!, on GTK2 works similar windows, (with the same problem), but in carbon doesn't work.

Thanks again for your time and work!

balazsszekely

  • Guest
Re: ListBox OnMeasureItem call it OnResize
« Reply #2 on: February 25, 2017, 07:44:54 am »
That c# code translated looks like this(create OnResize event for ListBox1):
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ListBox1Resize(Sender: TObject);
  2. const
  3.   LB_SETITEMHEIGHT = $01A0;
  4. var
  5.   H: Integer;
  6.   I: Integer;
  7.   MeasureItemEvent: TMeasureItemEvent;
  8. begin
  9.   MeasureItemEvent := ListBox1.OnMeasureItem;
  10.   if not Assigned(MeasureItemEvent) then
  11.     Exit;
  12.   for I := 0 to ListBox1.Count - 1 do
  13.   begin
  14.     MeasureItemEvent(TWinControl(ListBox1), I, H);
  15.     LCLIntF.SendMessage(ListBox1.Handle, LB_SETITEMHEIGHT, I, H);
  16.   end;
  17. end;

Edit: SendMessage is declared in lclintf.
« Last Edit: February 25, 2017, 07:57:20 am by GetMem »

lainz

  • Hero Member
  • *****
  • Posts: 4473
    • https://lainz.github.io/
Re: ListBox OnMeasureItem call it OnResize
« Reply #3 on: February 25, 2017, 12:23:52 pm »
Hi Lainz!, on GTK2 works similar windows, (with the same problem), but in carbon doesn't work.

Thanks again for your time and work!

Maybe it's the
Code: Pascal  [Select][+][-]
  1. LCLIntf.DrawText
that's not supported.

That c# code translated looks like this(create OnResize event for ListBox1):
...

Thanks GetMem, that works.

However seems that the height of the ListBox items has a limit or there's another bug in my code that limits the item height when the width is too small. But that's another problem, this one is solved.

balazsszekely

  • Guest
Re: [Solved] ListBox OnMeasureItem call it OnResize
« Reply #4 on: February 25, 2017, 03:43:23 pm »
I would draw into each item a TRichMemo and that would take care of text alignment on resize. Actually I did something similar in OPM with VST. VST works great on every major platform.
« Last Edit: February 25, 2017, 04:19:06 pm by GetMem »

 

TinyPortal © 2005-2018