c# - How should I name form controls variables and their event handlers in WinForms? -


I have a little coding style problem - what name should I choose in my name to control the Windows farm? I think the best method is not to generate everyone in the ( GenerateMember property) area, it can work on buttons, separators, menu items, etc.

But for example, some codes have labels and controls that require me to reference, modify, disable, etc. I currently designate them like this: lblInfo (Label), cbPerson (combobox), BTNOK - I think this is useful use of Hungarian notation. Their names begin in lowercase because they are the fields of the form

I select the name of the menu item based on their hierarchy - so this menu is FileExit, MenuEditCopy, etc.

The problem arises when I create an event handler for one of the controls - Visual Studio Autogenerate Handler such as:

btnOk_Click , menuEditCopy_Click - and StyleCop and I do not like any way to start with lowercase. I also do not like event handlers for the prefix separated by the name of the control of the event. To satisfy the coding standard, should I name the event handlers with the first letter in the first letter like BtnOk_Click ? Thanks

I personally change my control variable OkButton I'd call OnOkButtonClick for the event handler to focus on the functionality rather than typing> BTNok , which has the Formula + ControlName + event.


Comments