Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this questionThis 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 so开发者_运维技巧metimes 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..
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.
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.
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
精彩评论