Chapter 1 Introduction to Programming and C#Writing Windows Applications with C#PowerPoint PresentationProgramming LanguagesProgramming Languages cont.The Object ModelObject Model AnalogyMicrosoft’s Visual Studio.NETWriting C# ProgramsPlanningProgrammingC# Application FilesC# Application Files cont.The Visual Studio EnvironmentThe Visual Studio Environment cont.Slide 16Slide 17Slide 18Slide 19Slide 20C# ModesC# EventsC# Event-Handling MethodsC# Code StatementsC# Code Statements cont.Slide 26Coding Event-Handling Methods for Hello WorldSlide 28Some Control PropertiesSyntax ErrorsRun-Time ErrorsLogic ErrorsProject DebuggingNaming RulesOther IssuesChapter 2 More ControlsIntroducing More ControlsText BoxesGroup BoxesCheck BoxesRadio ButtonsPicture BoxesSetting a Border and StyleDrawing a LineSelecting Multiple ControlsControls as a GroupDesigning the User InterfaceDefining Keyboard Access KeysSetting the Accept and Cancel ButtonsSlide 50Chapter 1Introduction to Programming and C#Programming in C# .NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.2Writing Windows Applications with C#Projects look and act like standard Windows programsC# and Windows Forms tools will be usedGraphical User Interface (GUI) includesFormsControlsObject-oriented programming – everything in .NET is an object34Programming LanguagesProceduralSpecify exact sequence of all operationsIncludes BASIC, C, COBOL, FORTRAN, PL/I and PascalEvent DrivenProvided many elements of an object oriented languageIncludes early versions of Visual Basic5Programming Languages cont.Object OrientedPrograms are not proceduralProgrammer determines the exact sequence of instructions to be executedUser actions cause events to occurIncludes C# and Visual Basic. NET6The Object ModelObjects – a thing or a nounProperties – adjectives that describe objectsMethods – actions associated with objectsEvents – occur when the user takes an action or as the result of an action by another objectClasses – a template used to create a new object7Object Model AnalogyAn individual car is an objectMake, model, color, engine, and number of doors are properties of the carMethods of the car might include Start, SpeedUp, SlowDown, and StopEvents of the car might include Arrive or CrashA car is an instance of the Automobile class8Microsoft’s Visual Studio.NETIncludes C#, Visual Basic, Visual C++, and the .NET FrameworkThe Framework allows objects from different languages to operate together (interoperability)All .NET languages compile to Microsoft Intermediate Language (MSIL).exe.dllManaged code runs in the Common Language Runtime (CLR)9Writing C# ProgramsThree step process for planning and creating the project:Setting up the user interfaceDefining the propertiesCreating the code10PlanningDesign the user interfaceDraw a sketch of the screensConsult with the userPlan the propertiesWrite down properties to be set or changedPlan the C# codePlan classes and methodsDetermine events to codeWrite actions in pseudocode11ProgrammingDefine the user interfaceCreate required forms and controls (objects)Set the propertiesGive each object a nameDefine required attributes of each objectWrite the codeWrite C# programming statements to carry out actions12C# Application FilesA solution consists of one or more projectsEach project can have one or more form filesOther files are created when you run your project13C# Application Files cont..sln The solution file.suo Solution user options file.cs Holds definition of a form, its controls, and code statements.resx Resource file for a form.csproj A project file.csproj.user The project user option file14The Visual Studio EnvironmentVisual Studio is an integrated development environment (IDE) used by all .NET languagesThe IDE consists of tools includingForm designerEditorCompilerDebuggerObject browserHelp facility15The Visual Studio Environment cont.The IDE Start PageThe New Project DialogThe IDE Main WindowThe ToolbarsThe Document WindowThe Form DesignerThe Solution Explorer WindowThe Properties WindowThe ToolboxHelp1617Select the type of project you want to createBe Sure to change the project name and check the Location18NB: There is a difference in the file name and the control nameBe sure to rename before starting19Must match control name2021C# ModesDesign time – Used to design the user interface and write codeRun time – Used for testing and running a projectDebug mode F5 or Debug / StartRun w/o debug Ctrl-F5 or Debug / Start without Debugging Start ButtonBreak time – Occurs when you get a run-time error or pause project execution22C# EventsC# events are caused by user actionsWrite code called event-handling methodsC# ignores events with no methodsDo not attempt to create Event handlers using using your own code23C# Event-Handling MethodsA method is a set of statements beginning with a function headerMethod statements are enclosed in braces {}Event handlers are automatically named with formatObjectName_EventNameBasic event-handling method syntaxprivate void ObjectName_EventName( . . . ){Statements in the method} private void frmMyForm_Load(object sender, System.EventArgs e) { }24C# Code StatementsComment statementUsed for project documentationProgrammers should include comments to clarify their projectsSingle-line comments begin with double slashes //Example: //Exit the projectMultiline comments begin with /* and end with */Example: /* Programmer: Bradley/Millspaugh Date: June 2004 */Add to Task List // TODO: reminder comment25C# Code Statements cont.Terminate most C# statements with a semicolon (;)Assignment statement Assigns a value to a property or variableOperate from left to rightGeneral form Object.Property = value;Literals are enclosed in double quotation marksExample: titleLabel.Text = “A Snazzy Program”;Numbers and true/ false do not use quotation marks26C# Code Statements cont.Syntax to execute a method of an objectObject.Method();Methods always have parenthesisYou’ll get a syntax error if you forgetProperties do not have parenthesisMethod to terminate execution this.Close; // meaning this formthis refers to the current object and
View Full Document