views:

49

answers:

3

This can be applied to any language/UI project. When the code is automatically generated, is there a need to name all of the UI controls? Presently I only name the ones I am referencing in code (although admittedly sometimes I get lazy and leave them). Or do you stick with the pre-generated names (textbox1, splitContainer1, menuStrip1, etc..)?

If you name them, how do you prevent overlap such as MyDataGridView1, MyDataGridView2, etc..

+1  A: 

I only name the ones I reference too - most modern IDEs will easily rename a widget later if I need to reference it in code.

I usually give the names some meaning - accountDataView, currentBalanceDataView - it must relate to a concept like submitButton for the button that submits a form.

Vitor Py
A: 

I always try to set GenerateMember to false for the controls I don't use in the code, but for the controls I do use in code, I usually choose meaningful names.

For example, if there was a button that submitted something then I would choose submitBtn. If there was a username textbox then I would call it usernameTxt. Etc, etc.

A small list:

  • Buttons: btn
  • Textboxes: txt
  • Labels: lbl
  • Checkboxes: chk
  • Radio buttons: rad
  • List boxes: lst
  • Dialogs: dlg

...but above all else, just use what makes sense.

icktoofay
Inverse hungarian, unusual.
Hans Passant
this is interesting notation, permits to "directly" accede the "good-meaning" member name by the auto-complete. In this case the Hungarian suffix seems to be useless. I use traditionnaly `btnOpen`, `txtName` etc...
serhio
Yes, I know it's unusual, but it works well for me.
icktoofay
Accepting as answer for reminding me of GenerateMember .. Just wish there was an option to make false the default.
esac
A: 

I name the controls that I access and have experimented with using the "ux" prefix so that I can find them easily with Intellisense. That way if I can't remember the exact name of a control I know it at lease starts with ux. Also, if I change the control type, the name can stay the same. I came across this a while back, but can't seem to find the article about it now.

uxFirstName

jrm82