Changing the Name of a Form


The first thing you should do when you create a new object is give it a descriptive name, so that's the first thing I'll talk about in this hour. Start by opening the Picture Viewer project you completed in Hour 4, "Understanding Events." If you don't have this project, you can download it from my website.

Your Picture Viewer currently has some useful functionality, but it's not very flexible. In this hour, you'll start building an Options dialog box for the program. Add a new form for the dialog box by following these steps:

1.

Choose Project, Add Windows Form from the menu to display the Add New Item dialog box.

2.

In the Name text box, enter frmOptions.cs. This will be the name of your form as well as the name of the file that defines the form on the hard drive.

3.

Click the Add button (or double-click the Windows Form icon) to close the Add New Item dialog box and add the form to your project (see Figure 5.1).

Figure 5.1. Each new form starts off as a blank canvas.


You can change the name of a form using the (Name) property in the Properties window at any time, and doing so changes the name property of the form, (but not the name of the file on the hard disk). Whenever possible, give your forms solid names when you first create them.

By the Way

I'm a big fan of using three character naming prefixes, such as frm for form. I find it makes complicated code much more readable when objects have prefixes. I discuss naming conventions in Hour 11, "Using Constants, Data Types, Variables, and Arrays."





Sams Teach Yourself Microsoft Visual C# 2005 in 24 Hours, Complete Starter Kit
Sams Teach Yourself Visual C# 2005 in 24 Hours, Complete Starter Kit
ISBN: 0672327406
EAN: 2147483647
Year: N/A
Pages: 248
Authors: James Foxall

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net