0

I created simple project to show you my problem with TImage component. For example I added TCategoryPanelGroup, TCategoryPanel, TImage and two standard buttons which are use for hiding and showing Picture in TImage copomonent. You can see code for these buttons below:

unit Unit3;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons,
  Vcl.Imaging.jpeg, Vcl.ExtCtrls;

type
  TForm3 = class(TForm)
    CategoryPanelGroup1: TCategoryPanelGroup;
    CategoryPanel1: TCategoryPanel;
    imgTest: TImage;
    btnShow: TBitBtn;
    btnHide: TBitBtn;
    procedure btnHideClick(Sender: TObject);
    procedure btnShowClick(Sender: TObject);
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.btnHideClick(Sender: TObject);
begin
   imgTest.Visible := False;
   imgTest.Refresh;
   CategoryPanel1.Refresh;
   CategoryPanelGroup1.Refresh; // Refreshing TCategoryPanel Parent
   CategoryPanelGroup1.Invalidate;
   CategoryPanelGroup1.Repaint;

   { Just one way which I found to 'refresh'- hide image dynamically
   CategoryPanel1.Visible := False;
   CategoryPanel1.Visible := True;
   }
end;

procedure TForm3.btnShowClick(Sender: TObject);
begin
   imgTest.Visible := True;
   imgTest.Refresh;
   CategoryPanel1.Refresh;
   CategoryPanelGroup1.Refresh;
end;

end.

Unfortunatelly if we click on Hide button Picture stuck in the same place. If we would like refresh it we have to collapse and expand CategoryPanel1 (or uncomment the lines of code). Do you know how we can do it dynamically after click on button?

astack
  • 161
  • 4
  • 16
  • You don't need to call `Refresh` when changing a control's visibility, it triggers a repaint automatically. Nor should you be trying to `Refresh` an invisible control anyway, since there nothing to paint. What is the actual problem you are having? Have you tried calling `Refresh` on the CategoryPanel's `Parent` instead of the panel itself? Or even on the Form itself? And you generally should use `Invalidate()` instead of `Repaint()` since you are returning control to the main message loop soon afterwards. `Repaint()` is only needed when you want an immediate repaint while doing other things. – Remy Lebeau Oct 06 '15 at 20:43
  • The actual problem is that Picture isn't hiding dynamically. Even I tried calling Refresh for CategoryPanel's Parent or use Invalidate() function it doesn't work and I have still the same issue. – astack Oct 06 '15 at 20:59
  • 1
    `TImage` is a `TGraphicControl` descendant. It has no `HWND` of its own, it draws on its `Parent` when its `Parent` is redrawn by the OS. If the `Picture` is not being cleared onscreen, it likely means the `Parent` (or a grandparent) is not being redrawn so the `TImage` can draw (or not) on its `Parent` as needed. A `Refresh()`/`Invalidate()` on the `Parent` should have addressed that. So something else has to be blocking painting messages. Unless `TCategoryPanel` itself is just plain buggy when it comes to painting (which I doubt, since it has been around for awhile). – Remy Lebeau Oct 06 '15 at 22:03
  • Can you please provide a [MCVE](http://stackoverflow.com/help/mcve) that demonstrates the problem. And also, which version of Delphi are you using? – Remy Lebeau Oct 06 '15 at 22:05
  • @RemyLebeau I edited my post above. I think it can be issue with buggy TCategoryPanel. If you have another ideas I will be grateful, because I need use this panel in my project. – astack Oct 07 '15 at 16:16
  • After looking for an idea how to fix this issue I found workaround. I noticed this issue is related with buggy TCategoryPanel group component which doesn't repaint properly. Similar issue you can find here: [TCategoryPanelGroup does not repaint](http://qc.embarcadero.com/wc/qcmain.aspx?d=107947). My solution is to set DoubleBuffered property to true for TCategoryPanel. Thanks to it we reduce the amount of flicker when the control repaints, but we have to remember it's more memory intensive. – astack Oct 26 '15 at 20:48

0 Answers0