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 &quot;gooey&quot;.
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.
Programming in Visual C# 2005 Chapter 1 Introduction to Programming and C#
Point to a resizing handle and drag to resize Resize a selected control Point inside control and drag to a new location Move a selected control Press the Delete key Delete a selected control Click on it Select a control