FREE BOOK

Chapter 3: How to code and test a Windows Forms application using C# 2008

Posted by Murach Free Book | Windows Forms December 10, 2008
In this chapter, you'll learn how to code and test a Windows Forms application. When you're done, you'll be able to develop simple applications of your own.

How to get help information

As you develop applications in C#, it's likely that you'll need some additional information about the IDE, the C# language, an object, property, method, or event,or some other aspect of C# programming. Figure 3-13 shows several ways you can
get that information.

When you're working in the Code Editor or the Form Designer, the quickest way to get help information is to press F1 while the insertion point is in a keyword or an object is selected. Then, Visual Studio opens a separate Help window like the one shown in this figure and displays the available information about the selected keyword or object. Another way to launch a Help window is to select a command from Visual Studio's Help menu such as the Search, Contents, or Index command.

The Help window is split into two panes. The right pane shows the last help topic that you accessed. In this figure, for example, the right pane displays a help topic that provides information about working with the Code Editor.

The left pane, on the other hand, displays the Index, Contents, and Help Favorites tabs that help you locate help topics. In this figure, for example, the left pane displays the Index tab. At the top of this tab, the drop-down list has been used to filter help topics so they're appropriate for C# programmers. In addition, "codee" has been entered to navigate to the index entries that begin with those letters, and the Code Editor entry has been selected.

In addition to the topic that's displayed in the right pane, all the topics that are available for a selected entry are listed in the Index Results window that's displayed across the bottom of the screen. When the Code Editor entry was selected in this figure, for example, four topics were listed in the Index Results window and the first topic was displayed by default. To display another topic, you simply click on it.

In the left pane, you can click on the Contents tab to display a list of help topics that are grouped by category. Or, you can click on the Help Favorites tab to view a list of your favorite help topics. At first, the Help Favorites tab won't contain any help topics. However, you can add topics to this tab by displaying a topic and clicking on the Add To Help Favorites button that's available from the toolbar.

You can display a Search tab in the right pane by clicking on the Search button in the toolbar. From this tab, you can enter a word or phrase to search for, along with the languages, technologies, and content you want to search. Then, when you click the Search button, the results are displayed in the tab and you can click a topic to display it.

When you display information in the Help window, you should realize that the Help window uses a built-in web browser to display help topics that are available from your computer and from the Internet. In addition, the Help window works much like a web browser. To jump to a related topic, you can click on a hyperlink. To move forward and backward through previously displayed topics, you can use the Forward and Back buttons. As a result, with a little practice, you shouldn't have much trouble using this window.

The Help window


 
Figure 3-12 How to get help information

Description

  • You can display a Help window by selecting an object in the Form Designer or positioning the insertion point in a keyword in the Code Editor and pressing F1.

  • You can also display a Help window by selecting a command (such as Index, Contents, or Search) from Visual Studio's Help menu.

  • The Help window works like a web browser and can display help topics that are available from your computer or from the Internet. You can use the buttons in its toolbar to navigate  between help topics or to add topics to your list of favorite topics.

  • The Help window is divided into two panes. The left pane displays the Index, Content, and Help Favorites tabs that let you locate the help topics you want to display. The right  pane displays each help topic in a separate window.

  • If you click on the Search button, the right pane will display a Search tab that lets you search for help topics by entering a word or phrase.

  • If you click on the How Do I button, the right pane will display a How Do I tab that lets you go to a topic by clicking on a link.

  • To close a tab, click on the Close button when the tab is active. To display a tab, click the tab or select it from the Active Files drop-down list that's next to the Close
    button.

How to run, test, and debug a project

After you enter the code for a project and correct any syntax errors that are detected as you enter this code, you can run the project. When the project runs, you can test it to make sure it works the way you want it to, and you can debug it to remove any programming errors you find.
 
How to run a project

As you learned in chapter 1, you can run a project by clicking the Start Debugging button in the Standard toolbar, selecting the Start Debugging  command from the Debug menu, or pressing the F5 key. This builds the  project if it hasn't been built already and causes the project's form to be displayed, as shown in figure 3-14. When you close this form, the application  ends. Then, you're returned to Visual Studio where you can continue working  on your program.

You can also build a project without running it as described in this figure. In most cases, though, you'll run the project so you can test and debug it.

If build errors are detected when you run a project, the errors are displayed in the Error List window, and you can use this window to identify and correct the errors. If it isn't already displayed, you can display this window by clicking on the Error List tab that's usually displayed at the bottom of the window, or by using the View Error List command. When you do that, you should realize that the errors will still be listed in the Error List window and highlighted in the Code Editor even after you've corrected them. The errors aren't cleared until you build the project again.

The form that's displayed when you run the Invoice Total project




Figure 3-13 How to run a project


Description

  • To run a project, click the Start Debugging button in the Standard toolbar, select the Debug Start Debugging menu command, or press the F5 key. This causes Visual Studio to build the project and create an assembly. Then, assuming that there are no build errors, the assembly is run so the project's form is displayed as shown above.

  • If syntax errors are detected when a project is built, they're listed in the Error List window and the project does not run.

  • To locate the statement that contains the error, you can double-click on the error description in the Error List window. After you've corrected all the errors, run the project again to rebuild  it and clear the errors.

  • You can build a project without running it by selecting the Build Build Solution command.

  • When you build a project for the first time, all of the components of the project are built. After that, only the components that have changed are rebuilt. To rebuild all components whether or not they've changed, use the Build Rebuild Solution command.

Total Pages : 10 678910

comments