0

I'm having trouble finding a site that goes into detail about naming conventions for the common controls of Visual Studio. Either a website or list would be appreciated.

I'm not looking for naming conventions for namespaces, classes, methods, or variables. I am looking for naming conventions for things like buttons and labels.

Justin Stryker
  • 373
  • 4
  • 13

3 Answers3

3

Best practices for C# GUI naming conventions?

It seems that this is still something of a theological war with no accepted convention in the wider community.

Community
  • 1
  • 1
satnhak
  • 9,407
  • 5
  • 63
  • 81
  • My pleasure; actually we were discussing this at work today as we have just been reviewing our coding standard. As a group we opted for controlNameDescribingNoun, i.e. comboBoxCustomerNames. One guy was all in favour of uxDescribingNoun, i.e. uxDescribingNoun; he said he had used that at a previous company and it seemed to work well. I personally feel like adding the type is quite helpful, but yes it is cumbersome. – satnhak Apr 08 '11 at 19:39
  • our convention is name it for what it does, so a save button is called "save" an add user button called "addUser", makes it nice and easy, you end up with save.Click += ... The only excepion is where you need to program against a label, which would otherwise match the name of an inter-active control, so it might gate the name "addUserLabel". Hungarian notion is not my favourite clutter to see in code – Adam Straughan Apr 08 '11 at 19:57
1

I typically use a rather simple convention:

_buttonSubmit (ASP:Button Called Submit)
_dropDownYear (ASP:DropDownList for Years)
_placeHolderSomething (ASP:PlaceHolder for something)

Now, winForms, WPF, or ASP.NET, I think it's a good idea to always prefix your name with the control type, so when using it in a code behind, you instantly know what it is.

_radioButtonOne

Without mousing over for intellisense, you can be sure it's a Radio Button, etc. In addition, the '_' in front usually separates it from local variables as an instance specific member.

_radioButtonOne.Checked = true;
someLocalVariable++;
Tejs
  • 40,736
  • 10
  • 68
  • 86
1

Not quite sure if there is an actuall standard, as lots of developers like to argue pro's and cons on humpback and other notations.

I just finished up my program at fanshawe, and throughout the years they have recommended using hungarian notation.

That being said, here is some exmaples of how we were taught;

lblName - label
txtName - text box
cmbName - combo box
drpName = drop down

Really, you want to associaite the variable name with what the variable actually is.

http://en.wikipedia.org/wiki/Hungarian_notation

clamchoda
  • 4,411
  • 2
  • 36
  • 74