I have some user controls in a windows form. I wonder
if i set the Font
property of the main form, will its child get a) a copy of the new
Font
property of the main form is set, its child controls get neither deep copy of System.Drawing.Font
object nor the reference to it. On assignment, parent form creates unmanaged font object handle. All child controls are subscribed to parent’s FontChanged event so they have a chance to grab this handle and use it later for text rendering. Font
property getter of a control returns parent’s Font if control’s Font property has not been set explicitly (or default font). System.Drawing.Font
object to Font
property of a control, a previously assigned System.Drawing.Font
object gets finalized and garbage-collected if no more references to it remain in your application. So yes, you can do this safely. System.Drawing.Font
object assigned to Font
property of a control is NOT getting disposed when the control is disposed, or another System.Drawing.Font
is assigned to Font
property. So you are safe to create a single System.Drawing.Font
object and assign it to multiple controls, which are created and disposed dynamically. You are also free to create multiple fonts and assign them to a control periodically to create some visual effects. Internal unmanaged font handles are managed by Windows Forms.