#597 – Naming Conventions for Event Handlers

It’s customary to use the following convention when naming event handlers:

objectName_EventName

For example, if you were attaching a handler for the Click event to a Button and the button was labeled “Like”, you might name the handler btnLike_Click.

    <StackPanel>
        <Label Content="Tractors"/>
        <Button Content="Like" Click="btnLike_Click"/>
    </StackPanel>

Even though the Button control isn’t actually named, you can still use meaningful control names when naming event handlers.  In the example above, I’ve used a the “btn” three-letter prefix to refer to a Button.  Some other common control prefixes for naming purposes are:

  • cbo – ComboBox
  • chk – CheckBox
  • cnv – Canvas
  • dg – DataGrid
  • lbo – ListBox
  • lbl – Label
  • mnu – Menu
  • sp – StackPanel
  • tbl – TextBlock
  • txt – TextBox
  • win – Window
Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #597 – Naming Conventions for Event Handlers

  1. Pingback: Dew Drop – July 9, 2012 (#1,359) | Alvin Ashcraft's Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: