Wil*_*ins 69 c# user-interface naming-conventions winforms
GUI,无论是用WinForms还是XAML编写,似乎在我看到的项目之间具有最广泛的命名约定.对于一个TextBox
人的名字的简单,我已经看到了各种命名约定:
TextBox tbName // Hungarian notation
TextBox txtName // Alternative Hungarian
TextBox NameTextBox // Not even camelCase
TextBox nameTextBox // Field after field with TextBox on the end
TextBox TextBoxName // Suggested in an answer...
TextBox textBoxName // Suggested in an answer...
TextBox uxName // Suggested in an answer...
TextBox name // Deceptive since you need name.Text to get the real value
TextBox textBox1 // Default name, as bad as you can get
Run Code Online (Sandbox Code Playgroud)
我通常会遵守所有.cs文件的StyleCop规则,并且看到其他人也这样做,但GUI往往会违反这些规则或变化很大.我没有看到任何专门引用GUI元素的Microsoft指南,而不仅仅是普通变量,甚至是在控制台应用程序之外应用的示例.
在GUI中命名元素的最佳实践是什么?
Nei*_*l N 75
我使用旧学校匈牙利语... txt用于TextBox,btn用于Button,然后是一个通用词,然后是一个更具体的词.即:
btnUserEmail
Run Code Online (Sandbox Code Playgroud)
曾经有很多人说过"omg那么老,VB6打电话!" 但是在UI Rich winforms应用程序中,我可以更快地找到并修改内容,因为通常您对控件的第一件事是它的类型,然后是类别,然后具体.虽然较新的风格命名约定人员试图记住他们命名的文本框.
Lee*_*Lee 29
我用:
TextBox nameTextBox;
Run Code Online (Sandbox Code Playgroud)
就像我会使用:
MailAddress homeAddress;
Run Code Online (Sandbox Code Playgroud)
其原因在于,在这些情况下,"TextBox"和"Address"描述了对象所代表的内容,而不是如何存储或使用它.但在另一种情况下,如存储一个人的全名,我会使用:
string fullName;
Run Code Online (Sandbox Code Playgroud)
不:
string fullNameString;
Run Code Online (Sandbox Code Playgroud)
因为"String"不描述对象所代表的内容,而只描述它的存储方式.
Chr*_*ter 12
与.NET中其他所有内容相同的约定:仅限驼峰大小写描述性名称,如果需要区分同一逻辑"事物"的不同类,则可选地后跟后缀.例如:
string name; // a name
TextBox nameText; // the control used to edit the name
Label nameLabel; // the control used to label the edit control
List<string> nameList; // a list of names
Run Code Online (Sandbox Code Playgroud)
无限期无休止.只要它们是一致的和描述性的,后缀是什么并不重要.
Bra*_*on 9
这不是我的发明,但我喜欢它:
TextBox uxName = new TextBox();
Label uxNameLabel = new Label();
Button uxAccept = new Button();
Run Code Online (Sandbox Code Playgroud)
我更喜欢这种匈牙利符号,因为我的所有UI控件都显示在智能感知的一个块中."用户体验"的用户体验.如果您将控件从文本框更改为组合框或其他内容,这也很好,因为名称不会更改.
归档时间: |
|
查看次数: |
35913 次 |
最近记录: |