Do I need to call TCanvas.Refresh after RestoreDC?

I support some code that contains the following:

Canvas.Refresh; SavedDC := SaveDC(Canvas.Handle); try // Paint Stuff to the Canvas finally RestoreDC(Canvas.Handle, SavedDC); Canvas.Refresh; end; 

I found out that TCanvas.Refresh is not like updating a component. This does not cause anything to paint, it simply invalidates the font, pen and canvas brush .

I do not understand why you called .Refresh before saving the DC, and then after restoring it. It is like defeating the goal of SaveDC / RestoreDC calls.

A more reasonable order for these calls is as follows:

 SaveDC(Canvas.Handle) Canvas.Refresh try // Do my painting finally RestoreDC(Canvas.Handle, SavedDC); end; 

Since I never saw or used the TCanvas.Refresh method, I wanted to check and make sure I understood correctly.

+4
source share
1 answer

Here is the explanation - http://edn.embarcadero.com/article/27786

The update call after RestoreDC ensures synchronization between the state of TCanvas and the context of the underlying device.

I'm not sure that calling Refresh before SaveDC is necessary in modern versions of Windows, but where there is nothing wrong with it.

I would recommend leaving the code as is.

+4
source

Source: https://habr.com/ru/post/1334676/


All Articles