13. Files for a C# Project Form files Project file Solution file Solution user options file C# File that runs the program Project user option file Resource File for the form
14.
15.
16.
17. The Visual Studio IDE Toolbox Main Document window Solution Explorer Properties window Each window can be moved, resized, closed, or customized
18.
19. Toolbox & Document Window Pin Toolbox open with pushpin icon Use tab to change to Editor to edit code Form Designer tab – Use to create form Main Document window
20. Help Filte r Help with specific tasks Selected topic Help Search Index Results – Select topic to display Help Favorites tab Help Contents tab Index tab
21.
22.
23.
24.
25.
26.
27.
28.
29.
30. Set Properties in the Properties Window Name of selected object Properties window Object box Settings box Namespace and class of selected object Selected property
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45. Write the Event Handlers Editor tab Form Designer tab Comment statement Assignment statement Execute the Close method to end the program run
46.
47. Run the Program (2 of 2) Click the Display button The message appears in the label Click the Exit button to end the program and return to Design time
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
Hinweis der Redaktion
Complete objectives from the text: at the completion of this chapter, you will be able to ... 1. Describe the process of visual program design and development. 2. Explain the term object-oriented programming. 3. Explain the concepts of classes, objects, properties, methods, and events. 4. List and describe the three steps for writing a C# program. 5. Describe the various files that make up a C# project. 6. Identify the elements in the Visual Studio environment. 7. Define design time , run time , and debug time. 8. Write, run, save, print, and modify your first C# program. 9. Identify syntax errors, run-time errors, and logic errors. 10. Look up C# topics in Help.
Click on each element type to see an arrow to the examples in the figures.
GUI is pronounced "gooey".
OOP terminology is used throughout the text. The theory is presented in Chapter 12.
Express Editions are available for (currently) free download from Microsoft. The version that is bundled with this text is an evaluation version of the Professional Edition. The evaluation version can be used for 180 days. The version supplied to schools in the Academic Alliance is the Professional Edition. All programs in this text can be done with the Express Edition and Visual Web Developer (also a free download from Microsoft).
Planning: Design the user interface—draw a sketch of the screens the user will see when running the project; include forms and all controls that are to be used including the names to be assigned Plan the properties—for each object write down the properties that you plan to set or change during the design of the form Plan the C# code—plan the methods that will execute when the project runs including determining which events require action to be taken and then make a step-by-step plan for the actions. Use english-like pseudocode for the actions, rather than follow C# syntax. Programming: Define the user interface--create forms and controls Set the properties--give each object a name and define attributes such as the contents of a label. Write the C# code—use C# programming statements to carry out the actions needed by the program
The next slide shows the files in a project.
HelloForm.cs – Code written by the programmer HelloForm.Designer.cs – Code automatically generated by the Form Designer. A beginning programmer should ignore this file. HelloForm.resx – Resource file for the form. Can contain graphics and text strings for display on the form. HelloWorld.csproj – Project file.A text file that lists the files included in the project. HelloWorld.sln – Solution file. A text file that lists the projects included in the solution. HelloWorld.suo – Solution User Options file. Keeps the state of the environment from one run to the next. If you delete this file, the IDE reverts to the defaults. Program.cs – An automatically-generated file that is used to begin execution of a C# application. In Chapter 6 we edit this file if we want to change the startup form. HelloWorld.csproj.user – Project User Option file. Holds settings for the state of the environment for the project.
Form Designer – Lay out the form (the user interface), adding the controls, such as buttons and boxes. Editor – Write and edit the C# code. Compiler – Convert the C# code into runnable code (MSIL – Microsoft Intermediate Language). Debugger – Includes tools to single-step through program statements and display intermediate results. Covered in Chapter 4. Object Browser – Shows classes, objects, properties, methods, and events of all system elements, as well as classes you write. Covered in Chapter 12. Help –Includes extensive documentation, both local and on the Web. Referred to as MSDN – Microsoft Developers’ Network.
The title bar indicates the current mode. For Design Time, only the solution name displays. For Run Time, the solution name and (Running) display. For Debug Time, the solution name and (Debugging) display.
Note: You also can begin a new project from the Start Page, if it is displaying. This text assumes it to be closed.
In the Options dialog box, select Show all settings . Expand the Environment node and click on Startup . Drop down the list for At startup and select Show empty environment . By default, Show Start Page is selected.
Draw the sketch by hand and label the form and controls with the names you plan to give them.
Snap lines appear as you draw or move controls on the form. They can help align lefts, rights, or the text base line of controls.
Select a control on the form and the control’s properties appear in the Properties window. The default name of the first label is “label1” and the Text property is also “label1”. The namespace is the library location that holds the definition of the Label class.
Set the AutoSize property to False so that it doesn’t disappear when deselected.
Naming conventions are covered later. This style is called camel casing, and is the preferred convention for naming objects.
The next slide describes changing the form’s name and file name.
If you change the name of the form’s class in the properties window, you also must manually change the name of the file. It’s much better to change the name of the file and allow the IDE to rename the form’s class to match.
Details for comments, statement terminators, assignment statements, and executing a method are covered in the following slides.
Changing the name or deleting an event-handling method causes an error unless the change is also made in the Properties window. C# creates a program statement that is hidden in the FormName.Designer.cs file that assigns the method to the event. Although you can change the line of code using the Editor, the better solution is to make the change in the Properties window.
The next two slides detail the rules and conventions
MSDN – Microsoft Developer Network library. A good way to begin using Help is to view the topics that demonstrate how to look up topics in Help.