如何防止 Visual Studio 在继承的控件中设置默认字体大小

发布于 2024-08-26 09:02:21 字数 498 浏览 5 评论 0原文

我的所有文本框都有一个基类,我想在该类中设置默认字体。所以我从这个开始:

  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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇纵 2024-09-02 09:02:21

覆盖/新建 Font 属性,并使用 Hidden 选项应用 DesignerSerializationVisibility 属性。

override/new the Font property, and apply the DesignerSerializationVisibility attribute with the Hidden option.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文