c# – Control naming guidelines

Question: Question:

Are there any guidelines for naming conventions for controls such as TextBox and Button?
Please let me know if there are any guidelines that you can refer to.

There was a naming convention for object Hungarian notation , but it seems to be from the VB6.0 era, guessing from the contents of the list.
Is the nomenclature for prefixing such controls currently deprecated?


If you follow the MSDNname guidelines , the control will be afield (private of his form in Windows Forms).

Use Pascal format for field names.
Do not use prefixes in field names. For example, do not use g_ or s_ to distinguish between static and non-static fields.

Seems to be the case.

However, there are cases where the prefix notation is recommended in the original StackOverflow, and it is difficult to measure what kind of naming style is practical.

TextBox txtName     // NG
TextBox name        // OK
TextBox nameTextBox // OK
TextBox uxName      // OK?(ローカル変数と区別したい時に使う?)

Is this kind of understanding all right?

Answer: Answer:

In the documentation for .NET Framework 4 on MSDN, there are " Design Guidelines for Class Library Developers ". The relevant part is:

Is not it. It's a lot different from the era of Hungarian notation … Rather, it's reminded that " Don't use Hungarian notation. " Roughly speaking, use PascalCasing for class method names and local variables. Is unified by using CamelCasing .

Also about the prefix:

Normally, you don't use abbreviations or acronyms. Using these makes the name confusing.

Do not use abbreviations or abbreviations as part of the identifier name.
For example, use OnBtnClick instead of OnButtonClick .
Do not use acronyms that are not widely accepted. Also, use it only when necessary.

It is recognized that the act of shortening the name is basically not good.


For naming around the UI, refer to Pete Brown's blog post , where he was involved in projects such as WinForm in the past. This article provides a discussion of naming rules and the reasons why Hungarian notation was dropped, and the naming of parts classes and local variables that handle parts is summarized in "Controls on Forms". The article also recommends reading the book " .NET Class Library Design (Microsoft.net Development Series) " with similar content.

Scroll to Top