Windows窗体字体问题第1部分 [英] Windows Form Fonts Questions Part 1

查看:162
本文介绍了Windows窗体字体问题第1部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在窗体中有一些用户控件。我不知道如果我设置主窗体的字体属性,


  1. ,其孩子将得到a)新的 Font 的副本,或b)对新的 Font 的引用,或c)什么都没有?


  2. 是否需要处理字体?例如,我可以安全地执行下面的代码吗?
    $ b

    form.Font = new Font(...);
    <?c $ c> Form 或 UserControl )是否会自动处理字体?

  3. / p>


谢谢,

Gilbert

解决方案


  1. Font属性是它自己的.NET对象。然而Winforms缓存本地Windows字体,它们的创建相当昂贵。 .NET包装对象非常小。

  2. 是的。代码很好,Font属性设置器已经处理了以前分配的字体。

  3. 是的,它由UserControl处理。而后者又由其父母自动处置。



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 Font, or b) a reference to the new Font, or c) nothing?

  2. Does a font need to be disposed? For example, can I do the following code safely?

    form.Font = new Font(...);

  3. Will a font get disposed automatically when the parent (Form or UserControl) is disposed?

Thanks,
Gilbert

解决方案

  1. 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.

  2. Yes. The code is fine, the Font property setter already disposes the previously assigned font.

  3. Yes, it is disposed by the UserControl. Which in turn is automatically disposed by its parent.

这篇关于Windows窗体字体问题第1部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆