问题描述
我在窗体中有一些用户控件。我不知道如果我设置主窗体的字体属性,-
,其孩子将得到a)新的 Font 的副本,或b)对新的 Font 的引用,或c)什么都没有?
-
是否需要处理字体?例如,我可以安全地执行下面的代码吗?
$ bform.Font = new Font(...);
Form 或 UserControl )是否会自动处理字体? -
/ p>
谢谢,
Gilbert
-
Font属性是它自己的.NET对象。然而Winforms缓存本地Windows字体,它们的创建相当昂贵。 .NET包装对象非常小。
-
是的。代码很好,Font属性设置器已经处理了以前分配的字体。
-
是的,它由UserControl处理。而后者又由其父母自动处置。
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, or b) a reference to the new Font, or c) nothing?
Does a font need to be disposed? For example, can I do the following code safely?
form.Font = new Font(...);
Will a font get disposed automatically when the parent (Form or UserControl) is disposed?
Thanks,
Gilbert
Both. The Font property is its own .NET object. Winforms however caches the native Windows font, they are fairly expensive to create. The .NET wrapper object is quite small.
Yes. The code is fine, the Font property setter already disposes the previously assigned font.
Yes, it is disposed by the UserControl. Which in turn is automatically disposed by its parent.
这篇关于Windows窗体字体问题第1部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!