St. Ambrose CSCI 480 - Introduction to Programming and C#

Unformatted text preview:

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 programsC# and Windows Forms tools will be usedGraphical User Interface (GUI) includesFormsControlsObject-oriented programming – everything in .NET is an object34Programming LanguagesProceduralSpecify exact sequence of all operationsIncludes BASIC, C, COBOL, FORTRAN, PL/I and PascalEvent DrivenProvided many elements of an object oriented languageIncludes early versions of Visual Basic5Programming Languages cont.Object OrientedPrograms are not proceduralProgrammer determines the exact sequence of instructions to be executedUser actions cause events to occurIncludes C# and Visual Basic. NET6The Object ModelObjects – a thing or a nounProperties – adjectives that describe objectsMethods – actions associated with objectsEvents – occur when the user takes an action or as the result of an action by another objectClasses – a template used to create a new object7Object Model AnalogyAn individual car is an objectMake, model, color, engine, and number of doors are properties of the carMethods of the car might include Start, SpeedUp, SlowDown, and StopEvents of the car might include Arrive or CrashA car is an instance of the Automobile class8Microsoft’s Visual Studio.NETIncludes C#, Visual Basic, Visual C++, and the .NET FrameworkThe Framework allows objects from different languages to operate together (interoperability)All .NET languages compile to Microsoft Intermediate Language (MSIL).exe.dllManaged code runs in the Common Language Runtime (CLR)9Writing C# ProgramsThree step process for planning and creating the project:Setting up the user interfaceDefining the propertiesCreating the code10PlanningDesign the user interfaceDraw a sketch of the screensConsult with the userPlan the propertiesWrite down properties to be set or changedPlan the C# codePlan classes and methodsDetermine events to codeWrite actions in pseudocode11ProgrammingDefine the user interfaceCreate required forms and controls (objects)Set the propertiesGive each object a nameDefine required attributes of each objectWrite the codeWrite C# programming statements to carry out actions12C# Application FilesA solution consists of one or more projectsEach project can have one or more form filesOther 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 EnvironmentVisual Studio is an integrated development environment (IDE) used by all .NET languagesThe IDE consists of tools includingForm designerEditorCompilerDebuggerObject browserHelp facility15The Visual Studio Environment cont.The IDE Start PageThe New Project DialogThe IDE Main WindowThe ToolbarsThe Document WindowThe Form DesignerThe Solution Explorer WindowThe Properties WindowThe ToolboxHelp1617Select 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# ModesDesign time – Used to design the user interface and write codeRun time – Used for testing and running a projectDebug mode F5 or Debug / StartRun w/o debug Ctrl-F5 or Debug / Start without Debugging Start ButtonBreak time – Occurs when you get a run-time error or pause project execution22C# EventsC# events are caused by user actionsWrite code called event-handling methodsC# ignores events with no methodsDo not attempt to create Event handlers using using your own code23C# Event-Handling MethodsA method is a set of statements beginning with a function headerMethod statements are enclosed in braces {}Event handlers are automatically named with formatObjectName_EventNameBasic event-handling method syntaxprivate void ObjectName_EventName( . . . ){Statements in the method} private void frmMyForm_Load(object sender, System.EventArgs e) { }24C# Code StatementsComment statementUsed for project documentationProgrammers should include comments to clarify their projectsSingle-line comments begin with double slashes //Example: //Exit the projectMultiline 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 variableOperate from left to rightGeneral 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 parenthesisYou’ll get a syntax error if you forgetProperties do not have parenthesisMethod to terminate execution this.Close; // meaning this formthis refers to the current object and


View Full Document

St. Ambrose CSCI 480 - Introduction to Programming and C#

Download Introduction to Programming and C#
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction to Programming and C# and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction to Programming and C# 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?