Visual Studio 设计器中向控件添加属性的首选方式是什么?
我需要向 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以测试它,但我认为使用表单设计器时定义不会被覆盖。仅当您删除并重新添加控件时。如果您复制一个控件,则该副本可能不具有该属性。我必须将控件从
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
toprotected
and that worked. I would think attributes would be the same.