Mega Code Archive

 
Categories / Delphi / Graphic
 

Prevent a control from Redrawing (Refreshing)

Title: prevent a control from Redrawing (Refreshing)? { Question: Is there a way to stop a component from refreshing until I've completed some processing? Answer: Yes. Most controls can be blocked from redrawing by sending a WM_SETREDRAW message with wParam = 0 to them. Once you have finished the changes you send another WM_SETREDRAW with wparam = 1. For a grid this would look like this: } { Frage: Gibt es eine Möglichkeit, dass sich eine Komponente solange nicht neu zeichnet, bis ich mit einer Verarbeitungsroutine fertig bin? Antwort: Ja. Die meisten Controls können "eingefroren" werden, indem man ihnen ein WM_SETREDRAW Nachricht mit wParam = 0 schickt. Danach kann man WM_SETREDRAW mit wparam = 1 schicken, um das Updaten wieder zulassen. Für ein Grid sieht es z.B so aus: } procedure LockControl(c: TWinControl; bLock: Boolean); begin if (c = nil) or (c.Handle = 0) then Exit; if bLock then SendMessage(c.Handle, WM_SETREDRAW, 0, 0) else begin SendMessage(c.Handle, WM_SETREDRAW, 1, 0); RedrawWindow(c.Handle, nil, 0, RDW_ERASE or RDW_FRAME or RDW_INVALIDATE or RDW_ALLCHILDREN); end; end; procedure TForm1.Button1Click(Sender: TObject); begin LockControl(DBGrid1, True); try // do convoluted things to the grid finally LockControl(DBGrid1, False); end; end; { A number of controls have a build-in way to do that, the BeginUpdate and EndUpdate methods. You often find these not on the control itself but on some object property that manages the controls data, e.g. for a TMemo you use Lines.BeginUpdate and Lines.EndUpdate. The EndUpdate automatically forces a redraw of the control. } { Viele Controls besitzen schon die Methoden BeginUpdate und EndUpdate. Meistens findest man diese Methoden nicht direkt beim Control aber bei einer Objekt Eigenschaft, welche diese Methoden aufweist. Bei einem TMemo kann man z.B Lines.BeginUpdate und Lines.EndUpdate aufrufen. Mit BeginUpdate kann man verhindern, daß die Bildschirmanzeige aktualisiert wird, wenn Einträge angehängt, gelöscht und eingefügt werden. EndUpdate veranlasst das Control neu zu zeichnen. }