Naming objects

If we are going to refer to objects when we write event handlers, the objects must have names. The development system gives each object a name automatically. Those default names are just the object's class followed by a unique number.

We could use those default names in our event handlers, but programmers generally make up names that give the class and purpose of the object. For example, in the first event handler program, I called the buttons btnStop and btnMessage and the text box txtOut. I could have chosen any names, but I stuck with the convention of using the class prefix "btn" for buttons and "txt" for text boxes. The second part of the name gives an idea of purpose of the object or its function.

Programmers generally follow this sort of convention in making up object names, and you should do the same. Here are some typical class prefixes:

Class Prefix Example
Button btn btnDisplayText
TextBox txt txtUserInput
PictureBox pic picShowPhoto
Label lbl lblAddress


Disclaimer: The views and opinions expressed on unofficial pages of California State University, Dominguez Hills faculty, staff or students are strictly those of the page authors. The content of these pages has not been reviewed or approved by California State University, Dominguez Hills.