Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you name controls on forms using the same convention as a private variable?

For some reason I never see this done. Is there a reason why not? For instance I like _blah for private variables, and at least in Windows Forms controls are by default private member variables, but I can't remember ever seeing them named that way. In the case that I am creating/storing control objects in local variables within a member function, it is especially useful to have some visual distinction.

like image 932
Luke Avatar asked Aug 13 '08 03:08

Luke


2 Answers

This might be counter-intuitive for some, but we use the dreaded Hungarian notation for UI elements.

The logic is simple: for any given data object you may have two or more controls associated with it. For example, you have a control that indicates a birth date on a text box, you will have:

  • the text box
  • a label indicating that the text box is for birth dates
  • a calendar control that will allow you to select a date

For that, I would have lblBirthDate for the label, txtBirthDate for the text box, and calBirthDate for the calendar control.

I am interested in hearing how others do this, however. :)

like image 81
Jon Limjap Avatar answered Sep 24 '22 06:09

Jon Limjap


Hungarian notation or not, I'm more curious if people prepend m_ or _ or whatever they use for standard private member variables.

like image 36
Luke Avatar answered Sep 25 '22 06:09

Luke