Visual Studio 设计器中向控件添加属性的首选方式是什么?

发布于 2024-11-28 01:26:53 字数 563 浏览 0 评论 0原文

我需要向 Windows 窗体项目中的某些控件添加属性。它需要看起来像这样:

C#

[Queryable()] private System.Windows.Forms.TextBox txtName;
[Queryable()] private System.Windows.Forms.DateTimePicker dtpDateOfBirth;

VB.NET

<Queryable()> Private WithEvents txtName As System.Windows.Forms.TextBox
<Queryable()> Private WithEvents dtpDateOfBirth As System.Windows.Forms.DateTimePicker

我可以进入并编辑设计器文件以获得或多或少的所需效果,但这些设计器文件有时会附带一个警告,即它们是自动生成的文件。我担心设计者可能会覆盖我对文件所做的任何更改。也就是说,有没有办法使用设计器向控件添加属性,或者有什么方法可以在单独的文件中添加属性?

I need to add attributes to certain controls in a Windows Forms project. It needs to look something like this:

C#

[Queryable()] private System.Windows.Forms.TextBox txtName;
[Queryable()] private System.Windows.Forms.DateTimePicker dtpDateOfBirth;

VB.NET

<Queryable()> Private WithEvents txtName As System.Windows.Forms.TextBox
<Queryable()> Private WithEvents dtpDateOfBirth As System.Windows.Forms.DateTimePicker

I can go in and edit the designer file to get more-or-less the desired effect, but those designer files sometimes come with the caveat that they are automatically-generated files. I'm worried that the designer might overwrite any changes that I make to the file. That said, is there a way to add attributes to controls using the designer or is there some way that I can add the attributes in a separate file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

一笔一画续写前缘 2024-12-05 01:26:53

您可以测试它,但我认为使用表单设计器时定义不会被覆盖。仅当您删除并重新添加控件时。如果您复制一个控件,则该副本可能不具有该属性。我必须将控件从 private 更改为 protected 并且有效。我认为属性是相同的。

You could test it, but I don't think the definition will get overwritten when using the forms designer. Only if you delete and re-add the control. Possibly if you copy a control the copy might not have the attribute on it. I have had to change controls from private to protected and that worked. I would think attributes would be the same.

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