Best practices for naming user controls?
I've created quite a few user controls to encapsulate GUI functionality used in multiple places in my app. I've noticed I usually have a tendency to describe the function of the control and tack "Control" on the end of the n开发者_Python百科ame, but not always. I'd like to standardize the naming and wanted to know if there's a best practice for naming User Controls in .NET?
Actually, Control is a pretty good suffix. Consider making a control for Name/Address, you want something in the name that marks it as GUI instead of Logical.
So I tend to use NameAddressControl.
I also suffix my user controls with "Control"
My typical structure for UI modules would look something like:
DataEntry
-> DataEntryForm
-> DataEntryAddressControl
-> DataEntryNameControl
-> DataEntryAddressItem
-> DataEntryAddressItemCollection
-> DataEntryConfirmationDialog
etc.
works well for our team
Try to stay with something familiar to the user unless you are coding directly for other coders. It is a proven reliability issue not to introduce nomenclature that end-user is not familiar with.
Like some of the others, we also use the Control suffix for our user controls. (ie ResPayerControl)
UI elements are the only thing that I still do Hungarian notation for. uctDoesSomething works for me.
This is mostly a preference thing but I find that when I'm selecting a control my thoughts go in the order of "what type of control would it be" and then "what does it do". In that case it makes sense to type out "uct" and let intellisense provide me the alternatives.
There are two methods I've seen used:
- LoginDateCalendarCtl
- UCLoginDateCalendar
firstNameLA.Text="Name:";
firstNameTI.Text="<Enter your name in this TextInput Control>";
1) lowcaseCamel because controls are default private
2) use suffix instead of prefix for intellisense, etc to pick up by name not type
3) include the type and not simply 'Control', to remind your mind of the real, weireded-out names of all those darn fancy-schmantzy ui comps you gots
精彩评论