如何获得控件字体的默认值? [英] How do i get the default value of a control's font?

查看:27
本文介绍了如何获得控件字体的默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取控件字体的默认值,以便确定它当前是否为默认值.

i am trying to get the default value of a control's font so i can determine if it is currently the default value.

如何获取控件字体的默认值?

How do i get the default value of a control's font?

尝试通过反射获取Font属性的DefaultValue属性:

i tried getting the DefaultValue attribute of the Font property through reflection:

// Gets the attributes for the property.
AttributeCollection attributes = TypeDescriptor.GetProperties(label1)["ForeColor"].Attributes;

//Find the "DefaultValue" attribute
DefaultValueAttribute myAttribute = (DefaultValueAttribute)attributes[typeof(DefaultValueAttribute)];

除了没有默认值属性(myAttribute 为空)

except there is no default value attribute (myAttribute is null)

然后我意识到有 AmbientValue 属性,这意味着属性的值来自控件的父级.

i then realized that there's the AmbientValue attribute, which means that the value of an attribute comes from a control's parent.

跟随一个控件的 control.Parent 链发现它们每个都有一个 AmbientValue 属性标签,一直到 Form.

Following a control up it's control.Parent chain finds each of them have an AmbientValue attribute tag, all the way up to Form.

  • label1 [AmbientValue](无默认值)
    • form1 [AmbientValue](无默认值)
      • null
      • label1 [AmbientValue] (no DefaultValue)
        • form1 [AmbientValue] (no DefaultValue)
          • null

          那么如何获得控件的Font 属性的默认值?

          So how do i get the default value of a control's Font property?

          推荐答案

          如果您在谈论 WinForms,我认为 Control.DefaultFont 属性应该会有所帮助.

          If you're talking about WinForms, I figure the Control.DefaultFont property should help.

          这篇关于如何获得控件字体的默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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