Jump to content
David Marcus

Canvas.Font not equal Font?

Recommended Posts

The Help for Vcl.Graphics.TCanvas.Font says:

 

"The Canvas.Font property is only guaranteed to equal the Font property if you have an owner-drawn listbox (where you are expected to use the canvas). Even in that case, it is only guaranteed to equal the Font property once the first paint message is underway. If you use a canvas inside an ownerdraw event, everything should work as expected. Using the canvas for a reason outside the scope of its intended usage may give unpredictable results."

 

https://docwiki.embarcadero.com/Libraries/Alexandria/en/Vcl.Graphics.TCanvas.Font

 

What does this mean? If I'm using the Canvas property of a control, do the properties of the Canvas (e.g., Handle, Font) agree with the control's?

 

Share this post


Link to post
On 12/28/2022 at 5:17 PM, David Marcus said:

What does this mean? If I'm using the Canvas property of a control, do the properties of the Canvas (e.g., Handle, Font) agree with the control's?

Only while the control is actively processing a paint operation invoked by the OS - ie, during a WM_PAINT or NM_CUSTOMDRAW or equivalent window message.  Before the control's virtual Paint() method is called, or its public OnPaint/OnDraw... events are fired, both allowing user code to handle custom drawing, the relevant control properties are assigned to the Canvas.  Outside of an active paint operation, the Canvas's properties are not guaranteed to match the control's properties, and likely will be defaults instead.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×