Showing posts with label refresh. Show all posts
Showing posts with label refresh. Show all posts

Thursday, 30 April 2015

How to refresh a treeview control

I recent development I have been working on uses a TTreeview control. The underlining classes that relate to the nodes of the control get updated and I reflect the state of the class as dynamic colour of the node text. This state change can happen every few seconds so I wanted to refresh the treeview at least every couple of seconds.

I read a few articles on how to do this but found the treeview would flicker. The best solution I found was simple, when I wanted to refresh just simply call the 'invalidiate' method, at first this did not work until I set the doublebuffered property to true and now it works really well.

Thursday, 22 November 2012

Screen flicker with gradient background

Recently I had a problem with flickering when resizing a screen due to a gradient background. The problem was mainly noticeable with control on top of the background. Below are a couple of snippets that might help.

First I tried this:

// Interface
procedure WMEraseBackground(var _message:TMessage); message WM_ERASEBKGND;

// Implementation
procedure TForm.WMEraseBackground(var _message: TMessage);
begin
    _message.Result := 1;
end;

This helped with the flicker on the gradient panel, but I noticed other issues with some other controls not painting correctly and a panel having a thicker border. Then I tried this:

// Interface
procedure WMEnterSizeMove(var Message:TWMMove); message WM_ENTERSIZEMOVE;
procedure WMExitSizeMove(var Message:TWMMove); message WM_EXITSIZEMOVE;

procedure TfrmMain.WMEnterSizeMove(var Message: TWMMove);
begin
    // Set controls to visible = false
end;

procedure TfrmMain.WMExitSizeMove(var Message: TWMMove);
begin
    // Set controls to visible = true
end;

Doing this really helped the other controls from flicking, when the user resizes the window the controls disappear and then reappear once the resize is complete.