[SOLVED] ListView flicker lazarus / 31-LCL ---------------------------------------------------------------------- Zaxxon · 2016-06-07 07:14 when you resize a listview there is a lot of flickering I've tried to overrride the WM_ERASEBKGND message by Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ListViewWndProc(var Msg:TMessage);begin  if Msg.msg=WM_ERASEBKGND then begin    Msg.Result:=1;  end  else begin  Self.OldListViewWndProc(Msg);    end;end;  and that removed the flicker, but that caused other issues. Is there a better way of getting rid of the flicker? Or is the flicker a bug? I'm using lazarus 1.6 / FPC 3.0.0 in win 7 64 bit. ---------------------------------------------------------------------- Michl · 2016-06-07 07:38 Quote from: Zaxxon on June 07, 2016, 09:14:47 amOr is the flicker a bug?Yes, it was a bug and should be fixed in Lazarus Trunk (http://bugs.freepascal.org/view.php?id=30076). You can try the patch in the bug report, if it works for you too?! ---------------------------------------------------------------------- balazsszekely · 2016-06-07 08:16 @Michl I work with lazarus trunk, but the project still flickers a lot. @Zaxxon I see you're under windows. Please test the attached project: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses windows;//...var  PrevWndProc: WNDPROC; function WndCallback(AHWND: HWND; uMsg: UINT; wParam: WParam; lParam: LParam): LRESULT; stdcall;begin  case uMsg of    WM_ENTERSIZEMOVE: begin      LockWindowUpdate(Form1.ListView1.Handle);      Form1.ListView1.Align := alNone;      Form1.ListView1.Width := 10000;      Form1.ListView1.Height := 10000;      Form1.DisableAlign;      LockWindowUpdate(0);    end;    WM_EXITSIZEMOVE: begin      LockWindowUpdate(Form1.ListView1.Handle);      Form1.ListView1.Align := alClient;      Form1.EnableAlign;      LockWindowUpdate(0);    end;  end;  Result := CallWindowProc(PrevWndProc, Ahwnd, uMsg, WParam, LParam);end; procedure TForm1.FormCreate(Sender: TObject);var I:Integer;    LI:TListItem;    B:Boolean;begin  Self.ListView1.DoubleBuffered:=True;  Self.ListView1.Font.Size:=11;  B:=True;  for I:=0 to 30 do begin    LI:=Self.ListView1.Items.Add;    LI.Caption:=IntToStr(Random(1000000));     if B then LI.SubItems.Add('Yes')    else LI.SubItems.Add('No');     B:=not B;  end;  PrevWndProc := Windows.WNDPROC(SetWindowLongPtr(Form1.Handle, GWL_WNDPROC, PtrInt(@WndCallback)));end; procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);begin  if Item.SubItems[0]='Yes' then Self.ListView1.Canvas.Brush.Color:=clBlue  else Self.ListView1.Canvas.Brush.Color:=clGreen;end; ---------------------------------------------------------------------- Zaxxon · 2016-06-07 08:24 GetMem, your version removed the flicker, Thanks! ---------------------------------------------------------------------- serbod · 2016-06-07 08:45 Another way - use VirtualTreeView ( http://wiki.freepascal.org/VirtualTreeview ). It not flickers, can be used as list and have many useful features. ---------------------------------------------------------------------- Zaxxon · 2016-06-07 09:55 A little update. GetMem : your solution don't work well if you have other aligned components, such as panels. So I contiuned on my first solution and used yours partially. I simply fill the areas that is not painted in the WM_ERASEBKGND message. It's not perfect, but it will work for now.  I attached the new version. ---------------------------------------------------------------------- balazsszekely · 2016-06-07 10:04 @Zaxxon In theory, when you resize or move a form, the controls should not be updated until the operation is completed. I think the easiest solution, which works in all cases(it might not be the most elegant though) is this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function WndCallback(AHWND: HWND; uMsg: UINT; wParam: WParam; lParam: LParam): LRESULT; stdcall;begin  case uMsg of    WM_ENTERSIZEMOVE: Form1.DisableAlign;    WM_EXITSIZEMOVE: Form1.EnableAlign;  end;  Result := CallWindowProc(PrevWndProc, Ahwnd, uMsg, WParam, LParam);end; PS: Thanks for your feedback and your example.