CST131 The Basics Page 1

CST131—The Basics 1 1 2 1 2 2 3 3 3 4 4 4 5 5 5 6 6 7 6 7 7 8 8 9 8 9 9 10 10 11 10 11 GUI’s Using Visual C#— The Basics CST131 GUI’s Using ...
6 downloads 0 Views 623KB Size
CST131—The Basics 1 1 2 1 2 2

3 3

3

4 4 4

5

5 5

6 6 7 6 7 7

8 8 9 8 9 9

10 10 11

10 11

GUI’s Using Visual C#— The Basics CST131 GUI’s Using Visual C#— The Basics Visual C# CST131 GUI’s Using Visual C#— The Basics  One of several languages included in Visual Studio and the .NET Framework Visual C# CST131 – Only language written exclusively for Visual Studio  One of several languages included in Visual Studio and the .NET Framework Visual C#  An evolution of past languages including C and C++ – Only language written exclusively for Visual Studio  One of several included Visual Studio and the .NET Framework – Simpler than languages those languages butinstill powerful  An evolution of past languages including C and C++ – Only language written exclusively for Visual Studio Types of Applications – Simpler than those languages but still powerful  An evolution of past languages including C and C++  The types of applications that can be written in C# include: Types of Applications – Simpler than those languages but still powerful – Windows Desktop applications, i.e. applications that use a ―Window‖ interface with  The types of applications that can be written in C# include: Types of Applications buttons, menus, toolbars, etc. – Windows Desktop applications, i.e. applications that use a ―Window‖ interface with  The types of applications thatincan be written C# include: – Web applications that run a browser andindeliver dynamic content buttons, menus, toolbars, etc. – Web Windows services Desktop that create applications, the ability i.e. applications to share data that over use the a ―Window‖ Internet among interface many with – Web applications that run in a browser and deliver dynamic content buttons, menus, toolbars, etc. diverse servers – Web services that create the ability to share data over the Internet among many –… Web as applications well as manythat types runofinapplications a browser and deliver dynamic content diverse servers – Web services that create the ability to share data over the Internet among many The .NET Framework –… as well as many types of applications diverse servers  The.NET .NETFramework Framework (currently in version 4) is a software framework for developing The – … as well as many types of applications applications for the Microsoft Windows OS  The.NET .NET Framework (currently in version 4) is a software framework for developing The – There Framework are alternatives for other operating systems applications for the Microsoft Windows OS The .NETaFramework (currently version 4) is several a software frameworklanguages for developing  Includes large software library,inand supports programming which – There are alternatives for other operating systems applications allows for language for the Microsoft interoperability Windows OS  Includes a large software library, and supports several programming languages which – There are alternatives for otherlanguages operatingthat systems  Available to all the programming .NET supports allows for language interoperability  Includes a large software library, and supports several programming languages which The Visualto Studio  Available all theIDE programming languages that .NET supports allows for language interoperability  Integrated Development Environment The Visualto Studio  Available all theIDE programming languages that .NET supports – The design-time environment  Integrated Development Environment The IDE bar,  In Visual additionStudio to the Title Menu bar, and Tool bar … – The design-time environment  Integrated Development Environment Components include:  In addition to the Title bar, Menu bar, and Tool bar … design-timewindows: environment – The Document the ―Code Editor‖ window and the ―Form Designer‖  Components include:  In window addition to the Title bar, Menu bar, and Tool bar … – The Document windows: the ―Code Editor‖ window and the ―Form Designer‖  Components include: ―Solution Explorer‖ window, ―Properties‖ window and ―Tool box‖ – The Tool windows: window – The Document windows: the ―Code Editor‖ window and the ―Form Designer‖ The Visual IDE ―Solution – The ToolStudio windows: Explorer‖ window, ―Properties‖ window and ―Tool box‖ window Visual IDE ―Solution Explorer‖ window, ―Properties‖ window and ―Tool box‖ The Document Windows – The ToolStudio windows:  Code Editor window is where the code (the program statements) that execute at runVisual Studio IDE The Document Windows time are entered  Code Editor window is where the code (the program statements) that execute at runThe Document  Form Designer Windows window is the document in which a user interface is designed time are entered  Code Editor window where the only code (the program statements) that execute at run– ―Windows Forms‖ is applications  Form Designer window is the document in which a user interface is designed time are entered – Programmer/developer places (drags and drops) controls onto the Form – ―Windows Forms‖ applications only ® dialog  Form windowa isMicrosoft the document in which a user interface is designed – TheDesigner Form becomes Windows window at run-time – Programmer/developer places (drags and drops) controls onto the Form – ―Windows Forms‖ applications only The Code Editor – The Form becomes a Microsoft Windows® dialog window at run-time – Programmer/developer places (drags and drops) controls onto the Form Code Editor The Tool Windows – The Form becomes a Microsoft Windows® dialog window at run-time  Solution Explorer CodeWindows Editor window contains the project contents, including a list of the files The Tool other components that make up the project  Solution Explorer window contains the project contents, including a list of the files The Tool Windows  Properties window allows developer to set the properties for selected items and other components that make up the project controls  Solution Explorer window contains the project contents, including a list of the files  Properties window allows developer to set the properties for selected items and  Toolbox other components contains prototypes that makefor up the the controls project that the developer places onto the Form controls  Properties window developer – ―Windows Forms‖allows applications onlyto set the properties for selected items and  Toolbox contains prototypes for the controls that the developer places onto the Form controls The Tool Windows – ―Windows Forms‖ applications only  Toolbox contains prototypes for the controls that the developer places onto the Form The Tool Windows Customizing the IDEapplications only (Page 1) – ―Windows Forms‖  At Tool times Windows the the IDE IDE windows, especially(Page Tool windows, may become misplaced and even The Customizing 1)

Page 1

 Toolbox contains prototypes other components that makefor up the the controls project that the developer places onto the Form  controls Solution Explorer window contains the project contents, including a list of the files

– ―Windows Forms‖allows applications onlyto set the properties for selected items and  Properties window developer CST131—The Basics  Toolbox contains prototypes other components that makefor up the the controls project that the developer places onto the Form 10 11 10 11 10 10 11 11 12 12 12 13 12 13 13 13 14 14 14 14 15 16 15 16 15 15 16 16 17 17 17 17 18 18 18 18

19 20 19 20 19

19 20 20

21 21

controls The Tool Windows  Properties – ―Windows window Forms‖allows applications developer onlyto set the properties for selected items and  Toolbox contains prototypes for the controls that the developer places onto the Form controls The Customizing Tool Windows the IDEapplications only (Page 1) – ―Windows Forms‖  Toolbox contains prototypes for the controls that the developer places onto the Form  At Tool times Windows the the IDE IDE windows, especially(Page Tool windows, may become misplaced and even The Customizing 1) – ―Windows Forms‖ applications only closed (not visible)  At Tool times Windows the the IDE IDE windows, especially(Page Tool windows, may become misplaced and even The Customizing – Any missing window can be retrieved by 1) selecting View from the menu bar and the closed (not visible) name the View menu Tool windows, may become misplaced and even  At window times the IDE from windows, especially Customizing the IDE (Page – Any missing window can be retrieved by 1) selecting View from the menu bar and the closed (not visible) Customizing the IDE (Page 2) name the View menu  At window times the IDE from windows, especially Tool windows, may become misplaced and even – Any missing window can be retrieved by selecting View from the menu bar and the  The Auto Hide feature allows a Tool window to be hidden inside the edge of the IDE closed (not visible) Customizing the from IDE the View menu (Page 2) window name window until the mouse hovers over it … – Any missing window can be retrieved by selecting View from the menu bar and the  The Auto Hide feature allows a Tool (Page window to be hidden inside the edge of the IDE Customizing the IDE the – Auto Hide is turned on and by clicking2) the ―push pin‖ icons— window name from Viewoffmenu window until the mouse hovers over it …  The Auto Hide feature allows a Tool window to be hidden inside the edge of the IDE Customizing IDE on and off by (Page 2) – Auto Hide the is turned clicking3) the ―push pin‖ icons— window until the mouse hovers over it …  When allHide else feature fails andallows the developer wants to to be gethidden the IDE tool windows their The Auto a Tool window inside the edge back of thetoIDE Customizing IDE – Auto Hide the is turned on and off by (Page clicking3) the ―push pin‖ icons— install defaults window until the: mouse hovers over it …  When all else fails and the developer wants to get the IDE tool windows back to their Customizing the IDE (Page 1. Select Window fromonthe menu bar – Auto Hide is turned and off by clicking3) the ―push pin‖ icons— install defaults: 2. Select the Reset Window Layout command the IDE Window menu back to their  When all else fails and the developer wants get the tool windows Customizing the IDE (Page 3)tofrom 1. Select Window from the menu bar install : 3. Clickdefaults the button to confirm Select Window Layout command the IDE Window menu back to their  2. When all the elseReset fails and the developer wants tofrom get the tool windows 1. Select Window from the menu bar Visual C# Console install defaults : Applications 3. Click the button to confirm 2. Select the Reset Window Layout command from the Window menu 1. Selectapplications Window from the menu bar of the graphical windows (Forms) environment  Console do not make use Visual C#the Console 3. Click Applications button to confirm 2. Select thea Reset Window Layout command theMS-DOS Windowcommand menu  They run in command prompt window similarfrom to the window  Console do not make use of the graphical windows (Forms) environment Visual C#applications Console Applications 3.Useful Click the button to confirm – for beginner/instructional programming  They run in a command prompt window similar to the MS-DOS command window Console do not make use graphical windows  Application is developed exclusively in of thethe ―Code Editor‖ window(Forms) environment Visual C#applications Console Applications – Useful for beginner/instructional programming  They run in a command prompt window similar to the MS-DOS command window Visual C#applications Console Applications Console do not make use graphical windows  Application is developed exclusively in of thethe ―Code Editor‖ window(Forms) environment – Useful for beginner/instructional programming  They run in a command prompt window similar to the MS-DOS command window Starting New Console Application Visual C#a Console Applications  Application is developed exclusively in the ―Code Editor‖ window(Page 1) – Useful for beginner/instructional programming  To create a new ―Console‖ application: Starting New Console Application Visual C#a Console Applications  Application is developed exclusively in the ―Code Editor‖ window(Page 1) 1. Click the File command on the menu bar  To create a newConsole ―Console‖ application: Visual Starting C#aNew Console New Application (Page 1) 2. Click from Applications the ―File‖ drop-down menu 1. Click the File command on the menu bar  To a newConsole ―Console‖ application: 3. create Click Project… from the ―New‖ submenu Starting New Application (Page 1) 2. ClickaNew from the ―File‖ drop-down menu 1. Click the File command on the menu bar Starting New Application (Page 2)  To a newConsole ―Console‖ application: 3. create ClickaProject… from the ―New‖ submenu 2. Click New from the ―File‖ drop-down menu 1. Click the File command on the menu bar  Alternately: Starting New Console Application (Page 2) 3. ClickaProject… from the ―New‖ submenu 2. Click the New on the ―Standard‖ toolbar  Alternately: Starting New Console Application 3. Project… from from the ―New‖ submenu 2. ClickaNew Project… the ―New Project‖ drop-down menu(Page 2) 1. Click the button on the ―Standard‖ toolbar  Alternately: 2) Starting New Console Application 2. ClickaNew Project… from the ―New Project‖ drop-down menu(Page 3) 1. Click the button on the ―Standard‖ toolbar Alternately:  In the ―New Project‖ dialog window: Starting New Console Application 2. ClickaNew Project… from the ―New Project‖ drop-down menu(Page 3) Click the―Windows‖ ―Standard‖ toolbar Templates‖ pane 1. Select in the button ―Visual on C#‖the group of the ―Installed  In the ―New Project‖ dialog window: Starting New Console Application (Page 3) ClickaNew Project… from the ―New Project‖ 2. Select ―Console Application‖ from the list ofdrop-down applicationmenu types 1. Select ―Windows‖ in the ―Visual C#‖ group of the ―Installed Templates‖ pane  In the ―New Project‖ dialog window: 3. Typeaproject ―Name:‖ Application and select its ―Location:‖ (the drive and folder Starting Console (Page 3)where it will 2. Select New ―Console Application‖ from the list of application types saved) 1. be Select ―Windows‖ in the ―Visual C#‖ group of the ―Installed Templates‖ pane  In ―New Project‖ dialog window: 3. the Type project ―Name:‖ and select its ―Location:‖ (the drive and folder where it will 4. ―CreateApplication‖ directory for solution‖ box checked () 2. Leave Select the ―Console from the listcheck of application types 1. be Select saved) ―Windows‖ in the ―Visual C#‖ group of the ―Installed Templates‖ pane 5. buttonand select its ―Location:‖ (the drive and folder where it will 3. Click Type the project ―Name:‖ 2. Leave 4. Select the ―Console ―CreateApplication‖ directory for from solution‖ the listcheck of application box checked types () be saved) The Window 3. New 5. Type Project Click the project ―Name:‖ buttonand select its ―Location:‖ (the drive and folder where it will 4. Leave the ―Create directory for solution‖ check box checked () be saved) The Editor Window New Window 5. Code Click Project the button 4. Leave the ―Create directory for solution‖ check box checked ()  All executable code must be placed inside a method within the Code Editor The Editor Window New Window 5. Code Click Project the button  The first method executed by a Visual C# program is named Main  AllNew executable code must be placed inside a method within the Code Editor The Editor Window Window – Code PlaceProject all statements to be executed for a simple console application inside {braces}  The first method executed by a Visual C# program is named Main of this method  All executable code must be placed inside a method within the Code Editor The Window – Code Place Editor all statements to be executed for a simple console application inside {braces} Infirst a new console application, Main isC# placed inside file with the default filename  –The method executed by a Visual program is anamed Main this method  Allof executable code must be placed inside a method within the Code Editor – ―Program.cs‖ Place all statements to be executed for a simple console application inside {braces}  –The Infirst a new method console executed application, by a Visual Main isC# placed program inside is anamed file with Main the default filename of this method The Methodto be executed (Page ―Program.cs‖ – WriteLine() Place all statements for a1)simple console application inside {braces} – In a new console application, Main is placed inside a file with the default filename  Member the Console class of thisofmethod The WriteLine() Method (Page 1)

Page 2

20

 executable must be placed inside a method within the Code Editor TheAllCode Editorcode Window

 The first method executed by a Visual C# program is named Main CST131—The Basics  All executable code must be placed inside a method within the Code Editor

21 21

22 22

23 23

24 24 25 25

26

26

27 27

28 28

– Place all statements to be executed for a simple console application inside {braces}  The first method executed by a Visual C# program is named Main of this method – Place all statements to be executed for a simple console application inside {braces} – In a new console application, Main is placed inside a file with the default filename of this method ―Program.cs‖ – In a new console application, Main is placed inside a file with the default filename The WriteLine() (Page 1) ―Program.cs‖Method  Member of the Console class The WriteLine() Method (Page 1)  Writes a string of characters to the console window  Member of the Console class – A string is a series of characters inside quotation marks, i.e. "My first C# program"  Writes a string of characters to the console window  Also adds a newline character to the end of the text string thereby positioning the – A string is a series of characters inside quotation marks, i.e. "My first C# program" console pointer at the beginning of the next line  Also adds a newline character to the end of the text string thereby positioning the The WriteLine() Method (Page console pointer at the beginning of the next2) line  Format: The WriteLine() Method (Page 2) Console.WriteLine(characters);  Format:  Example: Console.WriteLine(characters); Console.WriteLine("My first C# program");  Example: – Take note that all Visual C# statements must end with a semicolon (;) Console.WriteLine("My first C# program"); The ReadKey() Method – Take note that all Visual C# statements must end with a semicolon (;)  Member of the Console The ReadKey() Methodclass  Waits for a key to be pressed by user before continuing to the next statement (if any)  Member of the Console class – Often the last statement in a console application so the application does not end and  Waits for a key to be pressed by user before continuing to the next statement (if any) the prompt window close before the user can read the output – Often the last statement in a console application so the application does not end and  Format: the prompt window close before the user can read the output Console.ReadKey();  Format: First—Program.cs Console.ReadKey();

First—Program.cs IntelliSense  A Visual Studio feature that detects errors and suggests code to the programmer IntelliSense  Syntax errors are highlighted by a red ―squiggly‖ underline  A Visual Studio feature that detects errors and suggests code to the programmer  Code suggestions are displayed in a drop-down window as the developer types  Syntax errors are highlighted by a red ―squiggly‖ underline – Select a suggestion and press the key on the keyboard to insert it into the  Code suggestions are displayed in a drop-down window as the developer types code – Select a suggestion and press the key on the keyboard to insert it into the Saving (Page 1) codean Application  Even aan simple Visual C# application made up of more than a dozen files and folders Saving Application (Pageis 1)  It is better to use the Save All command (the second ―Save‖ button on the toolbar)  Even a simple Visual C# application is made up of more than a dozen files and folders which saves all files  It is better to use the Save All command (the second ―Save‖ button on the toolbar) – The Save command or button saves just the current document which saves all files Saving Application (Page – The an Save command or button saves2) just the current document  An application may be saved either by: Saving an Application (Page 2) – Clicking the ―Save all‖ button on the ―Standard‖ toolbar as per the image above  An application may be saved either by: – Selecting the File command from the Menu bar and then Save All from the ―File‖ – Clicking the ―Save all‖ button on the ―Standard‖ toolbar as per the image above menu – Selecting the File command from the Menu bar and then Save All from the ―File‖  Not necessary at this point to give files names: menu – Application name was entered when starting the new application  Not necessary at this point to give files names: – Individual filenames are assigned by default – Application name was entered when starting the new application Running an Application (Pageby1)default – Individual filenames are assigned  Runningan an Application application means (Page to execute Running 1) it  This mode in the Visual Studio IDE is known as run-time  Running an application means to execute it  An application may be executed either by:  This mode in the Visual Studio IDE is known as run-time – Clicking the ―Start debugging‖ button on the ―Standard‖ toolbar  An application may be executed either by: – Selecting the Debug command from the menu bar and then Start from the ―Debug‖ – Clicking the ―Start debugging‖ button on the ―Standard‖ toolbar menu – Selecting the Debug command from the menu bar and then Start from the ―Debug‖

Page 3

– Application name was entered when starting the new application  Running an application means to execute it

28 Basics Running an Application (Pageby1)default – Individual filenames are assigned CST131—The  This mode in the Visual Studio IDE is known as run-time 28

29 29 29

30 30 30

31 31 32 31 32 32

33 33 33

34 34 34

35 35 36 35 36 36

37

37

 Runningan an Application application means (Page to execute it Running  An application may be executed either1) by:  This mode in the Visual Studio IDE is known as run-time  Running application means to button executeonit the ―Standard‖ toolbar – Clickinganthe ―Start debugging‖  An application may be executed either by:  This mode inthe theDebug Visualcommand Studio IDEfrom is known as run-time – Selecting the menu bar and then Start from the ―Debug‖ – Clicking the ―Start debugging‖ button on the ―Standard‖ toolbar  Anmenu application may be executed either by: – Selecting the Debug command from the menu bar and then Start from the ―Debug‖ – Clicking the ―Start debugging‖ button Running (Page 2)on the ―Standard‖ toolbar menu an Application – Selecting the Debug command from the menu bar and then Start from the ―Debug‖  To stop an an application from executing and return to design-time mode: Running Application (Page 2) menu – Click the ―Stop Debugging‖ button on the ―Debug‖ toolbar as per the image above  To stop an an application from executing2) and return to design-time mode: Running Application – Select Stop Debugging from (Page the Debug menu – Click the ―Stop Debugging‖ button on the ―Debug‖ toolbar as per the image above  To an application and return to design-time mode: – Astop Console applicationfrom endsexecuting automatically after the last statement executes – Select Stop Debugging from the Debug menu – Click the ―Stop Debugging‖ button on the ―Debug‖ toolbar as per the image A Windows Forms application can be closed by clicking the Close ("x") buttonabove in the – A Console application ends automatically after the last statement executes – upper-right Select Stop Debugging from thewindow Debug menu corner of the Form – A Windows Forms application can be closed by clicking the Close ("x") button in the – A Console application ends automatically Opening an Existing Solution 1) after the last statement executes upper-right corner of the Form(Page window – A Windows Forms application can be closed by clicking the Close ("x") button in the 1. Click ―Open‖ button Solution on ―Standard‖ toolbar Opening an Existing 1) … upper-right corner of the Form(Page window – Or select Open File … from the File menu 1. Click ―Open‖ button Solution on ―Standard‖ toolbar … Opening an folder Existing (Page 1)project 2. Open the with same name as the – Or select Open File … from the File menu 1. button on ―Standard‖ toolbar … project with extension ―.sln‖) and click 3. Click Select―Open‖ the desired project (same name as the 2. Open the folder with same name as the project –theOrOpen select Open File … from the File menu button 3. Select the desired project (same name as the project with extension ―.sln‖) and click 2. –Open folder with same name as the project I.e. the ―First.sln‖ the Open button 3. –Select desired project (same name as the the filename project with ―.sln‖)Microsoft and click If nothe extensions are visible, hover over andextension look for ―Type: – I.e. ―First.sln‖ theVisual OpenStudio buttonSolution‖ – If no extensions are visible, hover over the filename and look for ―Type: Microsoft – I.e. ―First.sln‖ Opening anStudio Existing Solution Visual Solution‖ – If no extensions are visible, hover over the filename and look for ―Type: Microsoft Opening anStudio Existing Solution (Page 2) Visual Solution‖  Only one canSolution be open at a time Opening an project Existing (Page 2)… – Opening one project closes the previous one  Only one project canSolution be open at a time … Opening (Page 2) – Clickan theExisting button in response to: – Opening one project closes the previous one  Only one project at a time … Do you want to close the current solution  ―The selectedcan filebe … open is a solution file. – Click the button in response to: – Opening onethis project closes the previous one and open file as the solution‖  ―The selected file … is a solution file. Do you want to close the current solution the button in response the to: ―Program.cs‖ filename in Solution Explorer  –If Click the code is not visible , double-click and open this file as the solution‖  ―The selected file … is a solution file. Do you want to close the current solution TheIfError ListisWindow  the code not visible, double-click the ―Program.cs‖ filename in Solution Explorer and open this file as the solution‖  Syntax—the rules a programmer must follow when coding The Listlanguage  IfError the code isWindow not visible, double-click the ―Program.cs‖ filename in Solution Explorer – Start by remembering Visual C# is case sensitive  Syntax—the language rules a programmer must follow when coding The List Window  TheError ―Error List‖ window keeps track of syntax errors that currently exist in the program – Start by remembering Visual C# is case sensitive  Syntax—the language rules before a programmer must follow when coding – These must be corrected the application will compile and execute successfully  The ―Error List‖ window keeps track of syntax errors that currently exist in the program Start by remembering Visual C# isand casethe sensitive – Double-click on an error message insertion point (cursor) jumps to the line – These must be corrected before the application will compile and execute successfully  The ―Error windowofkeeps track ofthe syntax which is List‖ the location the related errorerrors that currently exist in the program – Double-click on an error message and the insertion point (cursor) jumps to the line – These must be corrected before the application will compile and execute successfully Visual C#is Windows Forms which the location of theApplications related the error – Double-click on an error message and the insertion point (cursor) jumps to the line  A user interface that is designed for running Windows-based ―Desktop‖ applications Visual C#isWindows Forms which the location of theApplications related the error  A window with a Title bar, border, minimum and maximum buttons, and close button  A userC# interface that is designed for running Windows-based ―Desktop‖ applications Visual Windows  The Form becomes aForms runningApplications ―Windows‖ dialog with which a user may interact, and  A window with a Title bar, border, minimum and maximum buttons, and close button  which A user can interface that is be moved ordesigned resized for running Windows-based ―Desktop‖ applications  The Form becomes a running ―Windows‖ dialog with which a user may interact, and  A window with a Title bar, border, minimum and maximum buttons, and close button The Visual Form or resized which can C# be moved  The Form becomes a running ―Windows‖ dialog with which a user may interact, and The Controls Visual Form or resized which can C# be moved  A new ―Windows Forms Application‖ starts with a single Form module file and the IDE The Controls Visual C# Form presents a Toolbox with basic visual objects  A new ―Windows Forms Application‖ starts with a single Form module file and the IDE Controls – These are controls that are drawn (dragged and dropped) onto the Form presents a Toolbox with basic visual objects  The A new controls ―Windows include: Forms Application‖ starts with a single Form module file and the IDE – These are controls that are drawn (dragged and dropped) onto the Form presents a Toolbox basic visual objects – Button, CheckBox,with ComboBox, Label, ListBox, MenuStrip and MenuItems,  The controls include: – RadioButton, These are controls thatToolStrip, are drawnStatusStrip, (dragged and TextBox, etc.dropped) onto the Form – Button, CheckBox, ComboBox, Label, ListBox, MenuStrip and MenuItems,  The controls include: Starting a New Windows Forms Application (Page 1) RadioButton, TextBox, ToolStrip, StatusStrip, etc. – Button, CheckBox, ComboBox, Label, ListBox, MenuStrip and MenuItems,  To create a newWindows ―WindowsForms Forms‖Application application: Starting a New (Page 1) RadioButton, TextBox, ToolStrip, StatusStrip, etc.

Page 4

36

 A new ―Windows Forms Application‖ starts with a single Form module file and the IDE Controls – These are controls that are drawn (dragged and dropped) onto the Form

presents a Toolbox with basic visual objects CST131—The Basics  The controls include: A new ―Windows Forms Application‖ starts with a single Form module file and the IDE

37 37 37

38 38 38 39 39 39

40 41 40 41 40 41

42 43 42 43 42 43 44 44 44

45

45 45

46 46

– These are controls that are drawn (dragged and dropped) onto the Form presents Toolbox with basic visual objects – Button,aCheckBox, ComboBox, Label, ListBox, MenuStrip and MenuItems,  The controls include: TextBox, etc.dropped) onto the Form – RadioButton, These are controls thatToolStrip, are drawnStatusStrip, (dragged and – Button, CheckBox, ComboBox, Label, ListBox, MenuStrip and MenuItems,  The controls include: Starting a New Windows Forms Application (Page 1) RadioButton, TextBox, ToolStrip, StatusStrip, etc. – Button, CheckBox, ComboBox, Label, ListBox, MenuStrip and MenuItems,  To create a newWindows ―WindowsForms Forms‖Application application: Starting a New (Page 1) RadioButton, TextBox, ToolStrip, StatusStrip, etc. 1. Click the File command on the menu bar  To create a newWindows ―WindowsForms Forms‖Application application: Starting New (Page 1) 2. ClickaNew from the ―File‖ drop-down menu 1. Click the File command on the menu bar  To create a new ―Windows Forms‖ application: 3. Click Project… from the ―New‖ submenu 2. Click New from the ―File‖ drop-down menu 1. Click the File command on the menu bar Starting New Windows Application (Page 2) 3. ClickaProject… from theForms ―New‖ submenu 2. Click New from the ―File‖ drop-down menu  Alternately: Starting New Windows Application (Page 2) 3. ClickaProject… from theForms ―New‖ submenu 1. Click the button on the ―Standard‖ toolbar  Alternately: Starting New Windows Forms Application (Page 2) 2. ClickaNew Project… from the ―New Project‖ drop-down menu 1. Click the button on the ―Standard‖ toolbar  Alternately: Starting New Windows Forms Application (Page 3) 2. ClickaNew Project… from the ―New Project‖ drop-down menu 1. Click the button on the ―Standard‖ toolbar  In the ―New Project‖ dialog window: Starting New Windows Forms Application (Page 3) 2. ClickaNew Project… from the ―New Project‖ drop-down menu 1. Select ―Windows‖ in the ―Visual C#‖ group of the ―Installed Templates‖ pane  In the ―New Project‖ dialog window: Starting a New Windows Application 2. Select ―Windows FormsForms Application‖ from the list of application types (Page 3) 1. Select ―Windows‖ in the ―Visual C#‖ group of the ―Installed Templates‖ pane  In ―New Project‖ dialog window: 3. the Type project ―Name:‖ and select its ―Location:‖ (the drive and folder where it will 2. Select ―Windows Forms Application‖ from the list of application types saved) 1. be Select ―Windows‖ in the ―Visual C#‖ group of the ―Installed Templates‖ pane 3. Type project ―Name:‖ and select its ―Location:‖ (the drive and folder where it will 4. ―CreateForms directory for solution‖ boxofchecked () types 2. Leave Select the ―Windows Application‖ fromcheck the list application be saved) 5. buttonand select its ―Location:‖ (the drive and folder where it will 3. Click Type the project ―Name:‖ 4. Leave the ―Create directory for solution‖ check box checked () be saved) The Window 5. New Click Project the button 4. Leave the ―Create directory for solution‖ check box checked () The New Window 5. Button Click Project theControl button  An Button event-oriented control clicked by the user as needed to execute code operations The Control New Project Window  Click is the default event for a Button but it also can be programmed to respond to  An Button event-oriented control clicked by the user as needed to execute code operations The Control other events …  Click is the default event for a Button but it also can be programmed to respond to – I.e. MouseDowncontrol and MouseHover  An event-oriented clicked by the user as needed to execute code operations other events … – Determines exactly what user has with and/or to keyboard  Click is the default event forthe a Button butdone it also canthe bemouse programmed respond to – I.e. MouseDown and MouseHover otherdecides events …  User when the event is executed – Determines exactly what the user has done with the mouse and/or keyboard – I.e. MouseDown and MouseHover The Visual C#when Formthe event is executed  User decides – Determines exactly what the user has done with the mouse and/or keyboard Properties (Page 1) The Visual C#when Formthe event is executed  User decides  Properties for many items (including(Page controls Properties 1)on the Form) are updated within the The Visual C# Form ―Properties‖ window  Properties for many items (including(Page controls Properties 1)on the Form) are updated within the  Click on an item (i.e. a Button) to view its properties ―Properties‖ window  Properties for many items (including(Page controls Properties 2)on the Form) are updated within the  Click on an item (i.e. a Button) to view its properties ―Properties‖ window  The Text property for a Form control(Page modifies Properties 2) the text displayed on or in or beside the  Click on an item (i.e. a Button) to view its properties item  The Text property for a Form control(Page modifies text displayed on or in or beside the Properties 2) theand – Type a new value for this property of a Button the text on the control is item updated  The Text property for a Form control modifies the text displayed on or in or beside the – Type a new value for this property of a Button and the text on the control is  Many item other control properties exist including: updated – Size Height) an object Type(Width a new and value for thisofproperty of a Button and the text on the control is  Many other control properties exist including: updated (text color) and BackColor – ForeColor – Size (Width and Height) of an object  Many other controltoproperties exist including: – (DataBindings) ―bind‖ a control to data from a database – ForeColor (text color) and BackColor – Size (Width and Height) of an object Event-Driven Programming (Pageto1)data from a database – (DataBindings) to ―bind‖ a control – ForeColor (text color) and BackColor  The process whereby an application to user action is called event handling Event-Driven Programming (Pageresponds – (DataBindings) to ―bind‖ a control to1)data from a database  The operating system (Microsoft Windows®) responds when an event occurs by  The process whereby an application responds to user action is called event handling Event-Driven Programming (Page 1) sending a message to a running program ®  The operating system (Microsoft Windows ) responds when an event occurs by  Some of the whereby Visual C#an Events includeresponds Click, KeyPress, MouseMove, etc. The process application to user action is calledMouseOver, event handling sending a message to a running program ® are dozens)  (there The operating system (Microsoft Windows ) responds when an event occurs by  Some of the Visual C# Events include Click, KeyPress, MouseMove, MouseOver, etc. sending a message to a running program Event-Driven Programming (Page 2) (there are dozens)  Some of the Visual C# Events include Click, KeyPress, MouseMove, MouseOver, etc.  Double-click on object (i.e. a Button) to Event-Driven Programming (Page 2)create a method that responds to its ―Click‖ (there are dozens) event

Page 5

Event-Driven Programming (Page sending a message a running program – (DataBindings) toto ―bind‖ a control to1)data from a database (there are dozens)

 The process Some of the whereby Visual C#an Events application include Click, KeyPress, to user action MouseMove, is calledMouseOver, event handling etc. CST131—The Basics 45 Event-Driven Programming (Pageresponds 1) 46 46

46 46 47 47

47 47 48 48 49 49 48 49 48 49

50 50

50 51 50 51 52 52 53 53 51 52 51 53 52 53

54 54 55 55 54 55 54 55

56 56

Event-Driven Programming (Page 2) ®) responds when an event occurs by are dozens)  (there The operating system (Microsoft Windows  The process whereby an application responds to user action is called event handling  sending Double-click a message on object to a (i.e. running a Button) program to a method that responds to its ―Click‖ ®) responds when an event occurs by Event-Driven (Page 2)create  The operatingProgramming system (Microsoft Windows event  Some of the Visual C# Events include Click, KeyPress, MouseMove, MouseOver, etc.  Double-click on object a Button) to create a method that responds to its ―Click‖ sending a message to a(i.e. running program  Example (there aremethod dozens)header:  event Some of the Visual C# Events include Click, KeyPress, MouseMove, MouseOver, etc. private void button1_Click(object … ) 2) Event-Driven Programming (Page  Example header: (there aremethod dozens) – Place all statements to be executed for the object and its event inside {braces} of  Double-click private void on button1_Click(object object (i.e. a Button) … )to create a method that responds to its ―Click‖ Event-Driven this methodProgramming (Page 2) event – Place all statements to be executed for the object and its event inside {braces} of  Double-click on object (i.e. a Button) to create a method that responds to its ―Click‖ The MessageBox.Show()  Example this method method header: Method event  Displays private void a message button1_Click(object in a dialog window …) The MessageBox.Show()  Example method header: Method – Click Placethe all statements button to be to close executed the window for the object and its event inside {braces} of  Displays a message in a dialog window private void button1_Click(object …) this method  Format: – Click button to close the window Placethe all statements to be executed for the object and its event inside {braces} of MessageBox.Show(" Display string"); The MessageBox.Show() Method this method  Format:  Example:  Displays a message inDisplay a dialog window MessageBox.Show(" string "); The MessageBox.Show() Method MessageBox.Show("My C# Windows program"); – Click the buttonfirst to close the window  Example:  Displays a message in a dialog window Second.Form1.cs  Format: MessageBox.Show("My C# Windows program"); – Click the buttonfirst to close the window MessageBox.Show("Display string"); Second.Form1.cs The “.Designer.cs” File (Page 1)  Format:  Example: MessageBox.Show(" Display string  Drawing the Form atFile run-time,(Page like"); all 1) Visual C# operations, requires coded instructions The “.Designer.cs” MessageBox.Show("My first C# Windows program"); Example:  This code resides in a file associated with the ―.cs‖ file with the extension  Drawing the Form at run-time, like all Visual C# operations, requires coded instructions Second.Form1.cs ―.Designer.cs‖ MessageBox.Show("My first C# Windows program");  This code resides in a file associated with the ―.cs‖ file with the extension  To “.Designer.cs” find this file, in Solution Explorer: The File (Page 1) Second.Form1.cs ―.Designer.cs‖ – ―Drill down‖ to the files associated with the Form by clicking the box with the plus  To find this in at Solution Explorer: Drawing thefile, Form run-time, like all 1) Visual C# operations, requires coded instructions The “.Designer.cs” (+) that precedesFile the Form’s(Page filename  This – ―Drill code down‖ resides to the in afiles file associated associated with with the the ―.cs‖ Formfile by with clicking thethe extension box with the plus – Double-click on the ―.Designer.cs‖ to operations, open it in the Code Editor  Drawing the Form at run-time, like allfilename Visual C# requires coded instructions (+) that precedes the Form’s filename ―.Designer.cs‖  This code resides in a file associated with the ―.cs‖ file with the extension The “.Designer.cs” File (Pagefilename 2)  To – Double-click find this file,on in the Solution ―.Designer.cs‖ Explorer: to open it in the Code Editor ―.Designer.cs‖  The – ―Drill ―Windows down‖ to Form the Designer files associated generated the Form is initially by clicking hiddenthe in box the editor with the plus The File (Pagewith 2) code‖  To “.Designer.cs” find this file, in Solution Explorer: (+) that filename – Click the precedes box with the plusForm’s (+) that is in front of the hidden code placeholder to expand  The ―Windows Form generated is initially hidden in box the editor – ―Drill down‖ to theDesigner files associated withcode‖ the Form by clicking the with the plus – the Double-click region that on contains the ―.Designer.cs‖ this code filename to open it in the Code Editor (+) that precedes the Form’s filename – Click the box with plus (+) that is in front of the hidden code placeholder to expand – Click the same box, now with(Page a minus the code again The “.Designer.cs” File 2) (-), totohide region that this code filename – the Double-click on contains the ―.Designer.cs‖ open it in the Code Editor Second—Form1.Designer.vb (Source Code)(Page 1)code – Click the same box, now with a minus to is hide the again  The ―Windows Form Designer generated code‖ initially hidden in the editor The “.Designer.cs” File (Page 2) (-), – Click the box with plus (+) that is in front of the hidden code placeholder Second—Form1.Designer.vb (Source Code)(Page 1) hidden in the editorto expand 2)  The ―Windows Form Designer generated code‖ is initially the region that contains this code – Click the box with plus (+) that is in front of the hidden code placeholder to expand Second—Form1.Designer.vb The TextBox Control (Source 2)code – Click the same box, now with a minusCode)(Page (-), to hide the again the region that contains this code  Allows text to be typed directly into application The TextBox Control Second—Form1.Designer.vb (Source 1)code again – Click the same box, now with a minusCode)(Page (-), to hide the  The Text property determines what text is displayed and can be modified during:  Allows text to be typed directly(Source into application Second—Form1.Designer.vb Code)(Page 2) 1) – Design-time  The Text property determines what text is displayed and can be modified during: Changing the value in the(Source Properties window The TextBox Control Second—Form1.Designer.vb Code)(Page 2) – Design-time – Run-time  Allows text to be typed directly into application Changing the value in the Properties window The TextBox Control Values typed in the box by the text useris displayed and can be modified during:  The Text property determines what – Run-time  Allows text to be typed directly into application An assignment statement using code, i.e. textBox1.Text = "My first C# Windows – Design-time typed in the box by the text useris displayed and can be modified during:  TheValues Text property what program usingdetermines TextBoxes"; Changing the value in the using Properties An assignment statement code,window i.e. textBox1.Text = "My first C# Windows – Design-time Third—Form1.Designer.cs – Run-time program using TextBoxes"; Changing the value in the Properties window Values typed in the box by the user Third—Form1.Designer.cs The Text Property – Run-time An assignment statement using code, i.e. textBox1.Text = "My first C# Windows  Determines what is displayed in user (or on or beside) an object, i.e. TextBox or Button Values typedtext in the box by the The Text Property program using TextBoxes";  Might beassignment modified instatement Propertiesusing window, byi.e. thetextBox1.Text user at run-time, or in a code An code, = "My first C# Windows  Determines what text is displayed in (or on or beside) an object, i.e. TextBox or Button Third—Form1.Designer.cs statement program using TextBoxes";  Might be modified in Properties window, by the user at run-time, or in a code  Run-time code format: The Text Property Third—Form1.Designer.cs statement Object.Text = "Value"/Variable/Formula;  Run-time code format: Determines what text is displayed in (or on or beside) an object, i.e. TextBox or Button The Text Property  Example:  Might Objectbe .Text modified = "Value in Properties "/Variable/window, Formula;by the user at run-time, or in a code  Determines what text first is displayed in (or program on or beside) object, i.e. TextBox or Button textBox1.Text = "My C# Windows usingan TextBoxes"; statement  Example:  Might be modified in Properties window, by the user at run-time, or in a code  Run-time The Label Control code = format: textBox1.Text "My first C# Windows program using TextBoxes"; statement Object .Text = "Value "/Variable ; onto the Form  Used to position unattached text/Formula anywhere The Label Control  Run-time code format:

Page 6

Object.Text = "Value"/Variable/Formula;  Run-time Determines code what format: text first is displayed in (or program on or beside) object, i.e. TextBox or Button textBox1.Text = "My C# Windows usingan TextBoxes";

 Example: CST131—The Basics  Might modified in Properties Objectbe .Text = "Value "/Variable/window, Formula;by the user at run-time, or in a code 56 56 56

57 56 58 57 59 57 58 58 59 57 59 58 59

60 61 60 60 61 61 60 61

62 63 62 62 63 63

62 63

64 64 64

64

65 66 65 65 66

The Label Control textBox1.Text = "My first C# Windows program using TextBoxes"; statement  Example:  to position unattached text anywhere onto the Form  Used Run-time code = format: The Label Control textBox1.Text "My first C# Windows program using TextBoxes";  Often placed near TextBoxes (or other controls) do not have descriptive labels of Object .Text = "Value "/Variable ; onto that  Used to position unattached text/Formula anywhere the Form The Label their own Control  Example: Often placed near TextBoxes (or other controls) that do not have descriptive labels of  The Usedcaption to position is modified unattached during text design-time anywhere by onto changing the Form the Text property textBox1.Text = "My first C# Windows program using TextBoxes"; their own  Often placed near TextBoxes (or other controls) that do not have descriptive labels of Third—Form1.Designer.cs  TheLabel caption is modified during (Revised) design-time by changing the Text property The their own Control Third—Form1.cs Third—Form1.Designer.cs (Revised) Usedcaption to position unattached text anywhere by onto the Form  The is modified during design-time changing the Text property  Often placed near TextBoxes (or other controls) that do not have descriptive labels of Third—Form1.Designer.cs Third—Form1.cs Visual Studio File Structure (Revised) their own  ThreeStudio levels of files: Third—Form1.cs Visual Structure  The caption isFile modified during design-time by changing the Text property – Solution file (.sln)  ThreeStudio levels of files: Third—Form1.Designer.cs (Revised) Visual File Structure One solution can consist of several projects including Visual Basic, Visual C++, – Solution file (.sln)  Three Visual levels C#, of files: etc. Third—Form1.cs One solution can consist of several projects including Visual Basic, Visual C++, – C# project (.csproj): Solution filefile (.sln) Visual C#, etc. Visual Studio File Structure One Information solution about can consist each module of several (including projectsfilename includingand Visual relative Basic, locations/path) Visual C++, – C# project file (.csproj):  Threethat levels make of files: up Visual C#, etc.project Information about each module (including filename and relative locations/path) – Module Solution C# project files filefile (.sln) (code (.csproj): and Form): (.cs & .Designer.cs) that make up project One solutionabout Information can consist the of several in the projects project including (the Form Visual andBasic, the locations/path) code Visual areC++, eachmodules module (including filename and relative – Module files (code and Form): (.cs & .Designer.cs) Visual that examples make C#,of up etc. modules) project Information about the modules in the project (the Form and the code are C# project (.csproj): – Module (code and in Form): (.csStudio & .Designer.cs) Layout of afiles C#file Solution Visual examples of modules) Information about the eachmodules module in (including the project filename (the Form and relative and the locations/path) code are Layout The Solution of a C# (.sln) Solution File in Visual Studio that make upmodules) project examples of  Information – Module in the (code Solution and in Form): file includes: (.csStudio & .Designer.cs) Layout of afiles C# Solution Visual The Solution (.sln) File Information about the modules in the project (theprojects Form and code – References to the path and filename of the specific thatthe make upare the  Information in the Solution file includes: The Solution (.sln) File solution examples of modules) – References to the path and filename of the specific projects that make up the  Information – Details in the Solution whichinconfiguration file includes: files are used to compile the entire application Layout of aregarding C# Solution Visual Studio solution  A– new ―Solution‖ is created whenever new is startedthat make up the References to the path and filenameaof the―Project‖ specific projects – Details regarding which configuration files are used to compile the entire application The Solution (.sln) File solution – Multiple projects of different types can exist within the solution, i.e. Visual C#, Visual  A new ―Solution‖ is created whenever a new ―Project‖ is started  Information in the C++, Solution etc. configuration file includes: files are used to compile the entire application – Basic, DetailsVisual regarding which – Multiple projects of different types can exist within the solution, i.e. Visual C#, Visual  A– new References ―Solution‖ to the is created path and whenever filenameaof new the―Project‖ specific projects is startedthat make up the Basic, Visual C++, etc. solution projects of different types can exist within the solution, i.e. Visual C#, Visual – Multiple The Project (.csproj) Filesconfiguration (Page 1)files are used to compile the entire application – Basic, Details Visual regarding C++,which etc. A new ―Solution‖ is created whenever a new ―Project‖ is started  Each Project file within the solution contains: The Project (.csproj) Files (Page 1) – Which Multipletype projects of project of different this is, types i.e. Console can exist application, within theWindows solution,Forms i.e. Visual application, C#, Visual  Each Project(.csproj) file withinFiles the solution contains: The Project (Page 1) Basic, Visual C++, etc. etc. – Which type of project this is, i.e. Console application, Windows Forms application, – References to within the path filename of each module (Form files, code files, and  Each Project file theand solution contains: etc. other modules) that make up i.e. theConsole project application, Windows Forms application, – Which type of project this is, – References to the path and filename each module (Form files, code files, and The Project (.csproj) Files (Page 1)of – Lists configuration files unique to the compilation of each project etc. other modules) that make up the project  Each – References Project file to within the project’s path theand solution namespaces filename contains: of each and assemblies module (Form files, code files, and – Lists configuration files unique to the compilation of each project other modules) that make up the project – Which type of project this is,(Page i.e. Console application, Windows Forms application, The Project (.csproj) Files 2) and – References to the project’s namespaces assemblies – Lists etc. configuration files unique to the compilation of each project  Some of the(.csproj) several types of C# projects: The Project Files (Page 2)of each path and namespaces filename module (Form files, code files, and – References to the project’s and assemblies – Console Application other modules) that make up the project  Some of the several types of C# projects: The Project (.csproj) Files (Page 2)window A project that runs in a command – Lists configuration Console Applicationfiles unique to the compilation of each project  Some of theForms severalApplication: types of C# projects: – Windows – References theruns project’s namespaces and assemblies A projectto that in a command window – Console Application A project that executes inside a Microsoft Windows® dialog Form on the Desktop – Windows Forms Application: The Project (.csproj) Files (Page 2)window A project that runs in a (Active command – ASP.NET Web Application Server Pages) A project that executes inside a Microsoft Windows® dialog Form on the Desktop  Some theForms several types C# projects: – Windows Aofproject that Application: runs in of a Web browser – Web Application (Active Server Pages) ® dialog Form on the Desktop – ASP.NET Console Application A project that executes inside a Microsoft Windowsto Usually interacts with information from a database provide dynamic Web A project that runs in a Web browser A project that runs in a command window – ASP.NET contentWeb Application (Active Server Pages) UsuallyForms interacts with information from a database to provide dynamic Web – Windows A project that Application: runs in a Web browser content ® dialog Form on the Desktop A project that executes inside a Microsoft Windowsto Usually interacts with information from a database provide dynamic Web – ASP.NET contentWeb Application (Active Server Pages) A project that runs in a Web browser Usually interacts with information from a database to provide dynamic Web

Page 7