C# 和 Windows 窗体控件命名指南

发布于 2024-10-01 11:44:02 字数 41 浏览 3 评论 0原文

有人对表单和控件(例如事件、按钮)的命名约定有任何指南/最佳实践吗?

Does anyone have any guidelines/best practices for naming conventions for Forms and controls (e.g., events, buttons)?

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

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

发布评论

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

评论(6

他不在意 2024-10-08 11:44:02

我通常使用 系统匈牙利表示法
示例:

btnSubmit:是按钮

lblAccountNum:变量是标签

I usually use Systems Hungarian notation
Example:

btnSubmit: is button

lblAccountNum : variable is a label

乖乖哒 2024-10-08 11:44:02

在WinForms中我通常使用后缀,例如:

submitButton
accountNumberLabel

等。

但是很多公司仍然使用前缀,就像anthares所说的那样。

In WinForms I usually use suffixes, so for example:

submitButton
accountNumberLabel

etc.

But a lot of companies still use a prefix, like anthares said.

别念他 2024-10-08 11:44:02

我不认为表单开发需要任何特殊规则; Microsoft .NET 命名指南涵盖了它。

我像应用程序中的任何其他类一样命名表单:MainFormSaveDialog 等。

我像类中的任何其他字段一样命名控件:okButtonnameTextBox 等。

I don't believe any special rules are needed for forms development; the Microsoft .NET naming guidelines cover it.

I name forms like any other class in the application: MainForm, SaveDialog, etc.

I name controls like any other field within a class: okButton, nameTextBox, etc.

百变从容 2024-10-08 11:44:02

下面的例子是大多数.net程序员使用的

Control: Label
Prefix : lbl
Example: lblFirstName

The following example is most of the .net programmer is used

Control: Label
Prefix : lbl
Example: lblFirstName
守不住的情 2024-10-08 11:44:02

我通常在完整的类名前面加上前缀,例如textBoxName。我发现它比三个字母前缀更容易阅读,并且与 IDE 生成的名称一致。我只命名由代码引用的控件。数据绑定的控件通常不需要名称。

I usually prefix the full class name e.g. textBoxName. I find it easier to read than three letter prefixes and it's consistent with the names that are generated by the IDE. I only name controls that are referred to by code. Controls that are databound usually don't need a name.

红墙和绿瓦 2024-10-08 11:44:02

大多数公司的前缀不是完整的类名而是一些类名缩写的原因如下:

  1. 大多数命名约定在 Visual Studio 2010 之前被批准
  2. 。所有 Visual Studio 版本 2010 之前 有他们的智能感知过滤器,其中包含“开头为”而不是包含之类的内容。

这就是为什么很多人/建筑师/领导者认为输入“txt”是一个更好的主意,并且智能感知将为您过滤所有文本框,因此您只需输入“E”即可获得 txtEmail。如果您有完整的类名,则需要键入“textBoxE”才能在智能感知中获得相同的结果。当你有复杂的用户界面时,这会增加很多过热的情况。

现在,使用 Visual Studio 2010,您可以获得更好的智能感知,因此您只需键入“em”,就可以轻松地在列表中看到“textBoxEmail”(以及电子邮件和其他一些包含“em”的内容) ”)。不过,我似乎更喜欢使用 2-3 或最多 4 个字母的缩写,这样我可以通过控件类型(特别是 UI)进行智能感知过滤,而不是必须键入文本框。我更喜欢它的原因是,即使您对某些控件类型(例如 RadGrid 的“rg”)感到困惑一段时间,您也需要 5 分钟 3-4 次来记住它,然后不假思索地开始输入。然而,如果您到处都有 radGrid,则需要敲击 7 笔才能找到将为您过滤的有意义的笔画(例如“radGridCustomers”中的“radGridC”)。

我确实同意,仅命名代码中引用的控件通常就足够了。

The reason that the prefixes are not the full class names in most of the companies but some abbreviations of the class name are as follows:

  1. Most of the naming conventions are approved before Visual Studio 2010.
  2. All Visual Studio versions before 2010 have their inteli sense filter with something like "starts with" instead of contains.

That's why a lot of people / architects / leaders decided it will be a better idea to type "txt" and inteli sense will filter all textboxes for you, so then you just type "E" for example and you get txtEmail. If you have the full class name, you will need to type "textBoxE" to get the same result in inteli sense. This adds a lot of overheat when you have complex UI.

Now with Visual Studio 2010 you get a better inteli sense so you can just type "em" and you can easilly see the "textBoxEmail" in the list (along with Email and some other things that contain "em"). Still I seem to prefer to have 2-3 or up ot 4 letters abbreviation that will allow me to filter in inteli sense by control type (specially for UI) than having to type textBox. The reason I prefer it is that even if you are puzzled for a while with some control type (e.g. "rg" for RadGrid) you will need 5 minutes 3-4 times to remember it and start typing without thinking about it. While if you have radGrid everywhere you will need to hit 7 strokes to get to the meaningful one that will filter for you (e.g. "radGridC" in "radGridCustomers").

I do agree that only naming controls that are referenced in the code is usually enough.

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