Windows Form Fonts Questions Part 1

后端 未结 4 923
小鲜肉
小鲜肉 2020-12-19 16:59

I have some user controls in a windows form. I wonder

  1. if i set the Font property of the main form, will its child get a) a copy of the new

4条回答
  •  生来不讨喜
    2020-12-19 17:24

    From what I can tell, the Font property of a control is used to determine the font settings to use when drawing the control, but the GDI Font associated with that property isn't used to do the drawing. A control won't care if the Font that's assigned to its Font property is disposed after it's assigned, or even before it's assigned. The control is clearly capable of using some hidden aspects of the Font object which are available even after it is Disposed to determine the appropriate attributes of the font, but I don't know whether it

    1. Uses the supplied Font object, if not disposed, or else creates its own temporary font object each time it has to draw something and disposes the temporary object immediately thereafter.
    2. Uses the supplied Font object, if not disposed, or else creates its own private font object which it will dispose of when either the Font property is reassigned or the control is disposed.
    3. Copies the font family, size, etc. from the Font object when the Font property is assigned, and does everything with its private temporary or persistent Font objects it creates itself.
    4. Copies the font family, size, etc. from the assigned Font object whenever it's necessary to draw something.

    The control certainly keeps a reference to the passed-in font object, if for no other reason than to supply it to the Font property getter. I have no idea, though, whether it's better to dispose the Font after assigning it, or whether it's better to keep a copy of the Font in the form and dispose it when the Form itself is disposed.

提交回复
热议问题