为什么 Visual Studio 设计器不希望我更改代码中的事件名称?
我有一个关于 C# 事件命名约定的问题:
private void button21_Click(object sender, EventArgs e) { /// CODE /// }
private void button22_Click(object sender, EventArgs e) { /// CODE /// }
private void button23_Click(object sender, EventArgs e) { /// CODE /// }
设计器警告我应该保持设计器代码不变。如果我无法在 designer.cs
文件中更改名称,那么如何将其更改为更有意义的名称?
I have a question about C# Event naming conventions:
private void button21_Click(object sender, EventArgs e) { /// CODE /// }
private void button22_Click(object sender, EventArgs e) { /// CODE /// }
private void button23_Click(object sender, EventArgs e) { /// CODE /// }
The designer warned that I should leave designer code unchanged. How then do I change the names to something more meaningful if I can't change it in the designer.cs
file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试更好地命名按钮。这样事件处理程序会读得更好。
Try naming the buttons better. That way the event handler will read better.
名称的问题在于编号。
默认情况下,设计者给出的对象名称如 classtypeN,其中 N 是一个递增的数字。
转到设计器,单击该对象,转到属性,然后在那里重命名。
这样你就不会和设计师发生冲突了
The issue with the names is the numbering.
the designer, by default, gives objects names like classtypeN where N is an increasing number.
Go to the designer, click on the object, go to the properties ,and rename it there.
Then you won't have your conflict with designer
我养成了一种习惯,将每个控件放在窗体上后首先对其进行重命名。我不喜欢返回并将所有事件处理程序从例如button1_Click 重命名为btnClickMe_Click。我使用的实际约定取决于项目的约定,但我总是尽量不要忘记重命名控件。
下面是包含一些常见控件前缀的链接。
http://support.microsoft.com/kb/173738
您也可以尝试 ux 或 _ux前缀样式
www.cyberbrutus.com/naming-conventions-c/
I developed a habit of renaming each control first thing after I drop them on a form. I don't like going back and renaming all event handlers from e.g. button1_Click to btnClickMe_Click. The actual convention I use depends on the project's convention but I always try not to forget about renaming controls.
Below is a link with some prefixes for common controls.
http://support.microsoft.com/kb/173738
You may also try the ux or _ux prefix style
www.cyberbrutus.com/naming-conventions-c/