如何防止 Visual Studio 在继承的控件中设置默认字体大小
我的所有文本框都有一个基类,我想在该类中设置默认字体。所以我从这个开始:
public partial class MyTextBox : TextBox
{
public WmlTextBox()
{
InitializeComponent();
//Font for the whole application can be altered in the Appearance class
Font = new Appearance().TextBoxFont;
}
}
然后我删除了表单中设置文本框字体的所有代码。当然,在我更改页面上的项目之前,这一切都很好。 Visual Studio 选择应用程序的默认字体(在 Appearance 类中设置),并在设计器中为所有 TextBox 生成代码以将其设置为该特定字体。如何阻止 Visual Studio 从我的默认字体生成代码? 我想允许开发人员更改属性,但我想集中设置默认字体。
I have a base class for all my textboxes and I want to set the default font in that class. So I started with this:
public partial class MyTextBox : TextBox
{
public WmlTextBox()
{
InitializeComponent();
//Font for the whole application can be altered in the Appearance class
Font = new Appearance().TextBoxFont;
}
}
I then stripped out all the code in the form that was setting the font of the textboxes. Of course this worked fine until I altered an item on the page. Visual Studio picked up the default font for the application (set in the Appearance class), and generated code in the designer for all TextBoxes to set it to that specific font. How can I stop visual studio from generating code from my default font?
I want to allow the developers to change the property, but I want to set the default font centrally.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
覆盖/新建
Font
属性,并使用Hidden
选项应用DesignerSerializationVisibility
属性。override/new the
Font
property, and apply theDesignerSerializationVisibility
attribute with theHidden
option.