Mega Code Archive

 
Categories / Delphi / Graphic
 

How to disable a graphic component from painting

Title: How to disable a graphic component from painting Question: When we add many lines in TMemo component in run-time, the user will see the lines beeing addes one by one. This will cuse the TMemo to flick and it will slow the application down. Answer: In the Windows API, there is a very helpfull function that it's name is LockWindowUpdate. This functions come in Windows 95 and above ! This function tells windows not to generate the paint message while this function is called. So how do we use it ? .... procedure TForm1.Button1Click(Sender : TObject); begin if Button1.Caption = 'Lock' then begin LockWindowUpdate(Memo1.Handle); Button1.Caption := 'UnLock'; end else begin LockWindowUpdate(null); Button1.Caption := 'Lock'; end; end; Who uses it ? When you for example Internet Explorer loding its graphic output, you see this white screen, and if you popup another window you can see it picture in the white area, then you can know that the painting is locked. The good thing in this function is that the component does paint itself, but it does not been drawon on the screen, only in memory !