Adding Features to a Windows Forms Application (4 of 5)

From webpage

Adding Features to a Windows Forms Application - How to name and save the files of a project

 
(Page 4 of 5 )

When you're working on a project, you may want to change the names of some of the files from their defaults. Then, you'll want to save the files with their new names.

How to name the files of a project

You may have noticed throughout this chapter that I didn't change the default name of the form (Form1.vb) that was added to the Invoice Total project when the project was created. In practice, though, you usually change the name of this form so it's more descriptive. For example, figure 2-9 shows how to use the Solution Explorer to change the name of the form file to frmInvoiceTotal.vb. When you do that, Visual Studio will also change the Name property for the form from Form1 to frmInvoiceTotal and modify any of the code that's been generated for the form accordingly.

You may also want to change the name of the project. Or, you may want to change the name of the solution so it's different from the project name. If so, you can use the technique presented in this figure to do that too.

How to save the files of a project

Figure 2-9 also describes how to save the files of a project. Because Visual Studio saves any changes you make to the files in a project when you build the project, you won't usually need to save them explicitly. However, it's easy to do if you need to.

Notice in this figure that two factors determine which files are saved: what's selected in the Solution Explorer and the command you use to perform the save operation. If, for example, a single file is selected, you can use the Save command to save just that file, and you can use the Save All command to save the file along with the project and solution that contain the file. In contrast, if a project is selected in the Solution Explorer, the Save command causes the entire project to be saved, and the Save All command causes the entire solution to be saved.

If you haven't saved all of your recent changes when you close a project, Visual Studio will ask whether you want to save them. As a result, you don't need to worry that your changes will be lost.

The Solution Explorer as a form file is being renamed

 

How to rename a file, project, or solution

  1. You can rename a file, project, or solution by right-clicking on it in the Solution Explorer window and selecting the Rename command from the shortcut menu. Or, you can select the file, project, or solution in the Solution Explorer and then press F2. Then, you can enter the new name for the file, project, or solution. 
  2. Be sure not to change or omit the file extension when you rename a file. Remember too that using a three-letter prefix to indicate the contents of the file (like frm for a form file) makes it easier to tell what each file represents. 
     
  3. When you change the name of a form file, Visual Studio will also change the Name property for the form and update any references within the existing code for the form, which is usually what you want.

 How to save a file, project, or solution

  • You can use the Save All button in the Standard toolbar or the Save All command in the File menu to save all files and projects in the solution. 
  • You can use the Save button in the Standard toolbar or the Save command in the File menu to save a file, project, or solution. The files that are saved depend on what's selected in the Solution Explorer window. If a single file is selected, just that file is saved. If a project is selected, the entire project and its solution are saved. And if a solution is selected, the entire solution and all its projects are saved. 
     
  • If you try to close a solution that contains modified files, a dialog box is displayed that asks you if you want to save those files.  

 

Figure 2-9.  How to name and save the files of a project


No comments: