表单上无法识别子类文本框只读字体
为用户界面控件构建我的基类已经完成了。 我有使用自定义字体分配派生的命令按钮并将其放在表单上,一切都很好...但是,在同一表单上无法正确识别文本框的只读属性字体的相同代码。 它仅采用表格的设置,而忽略其自己的字体声明。
public class MyTextbox : TextBox
{
[ReadOnly(true)]
public override Font Font
{ get { return new
Font( "Courier New", 12f, FontStyle.Regular, GraphicsUnit.Point );
}
}
}
Building my baseclasses for user interface controls is getting there. I have command buttons derived with custom font assignment and put on a form, all is fine... However, identical code for the read-only property Font of a textbox is NOT recognized properly on the same form. It is ONLY taking the setting of the FORM and disregarding its own Font declaration.
public class MyTextbox : TextBox
{
[ReadOnly(true)]
public override Font Font
{ get { return new
Font( "Courier New", 12f, FontStyle.Regular, GraphicsUnit.Point );
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Font 属性是环境属性。 如果从未分配过,它会自动匹配容器控件的 Font 属性。 你从来没有分配过它。
像这样做:
The Font property is an ambient property. If it was never assigned, it automatically matches the Font property of the container control. You never assigned it.
Do it like this:
在“nobugz”(谢谢)的帮助下,我在做 ComboBox 时也发现了同样的失败。 我的结果如下...
我的 getter
但是,在 nobugz 响应中,编译器的某些功能不太正常,因此在类的构造函数中
With a help from "nobugz" (Thanks), I found this same failure when doing a ComboBox too. My result was the following...
My getter
However, in nobugz response, something wasn't working quite right with the compiler, so in the constructor of the class