Presentation is loading. Please wait.

Presentation is loading. Please wait.

Neal Stublen Tonight’s Agenda  More form controls  Multi-form projects  Application debugging  Object-oriented programming and.

Similar presentations


Presentation on theme: "Neal Stublen Tonight’s Agenda  More form controls  Multi-form projects  Application debugging  Object-oriented programming and."— Presentation transcript:

1 Neal Stublen nstublen@jccc.edu

2 Tonight’s Agenda  More form controls  Multi-form projects  Application debugging  Object-oriented programming and classes  Q&A

3

4 Practice Exercise  Write a program that can record ten student grades What will you use to store the grades?  Find the average of those grades, but don’t include the lowest grade in the average How will you determine the lowest grade? How will you remove it from the average?

5

6 Radio Button  Grouped with other RadioButtons for mutually exclusive selection Property: Checked Event: CheckedChanged  Use a GroupBox to indicate which buttons are related

7 Checkbox  Turns a selection on or off Property: Checked Event: CheckedChanged  Can be indeterminate Property: CheckedState Event: CheckedStateChanged

8 ComboBox  Select one item from a group of items Property: SelectedIndex Event: SelectedIndexChanged  DropDownStyle Simple DropDown DropDownList

9 ListBox  Select one or more items from a list of items Property: SelectedIndex, SelectedIndices, SelectionMode Event: SelectedIndexChanged  Shift and Ctrl keys allow multiple selection

10 Group Box  Radio buttons can be grouped together  Controls in a group box move together  Grouping controls impacts tab order

11 View Help  Select any control on a form, press F1  Overview of controls  Key properties and methods

12 Which control to use?  Your application prints reports. Which control would you use to: Select one of many report template Show or hide page headers Select from no headers, brief headers, or verbose headers Select a printer when printing the report

13

14 Working with Forms  Additional forms can be added to a project  Load event typically initializes a form  Typically the form’s name matches the file where it is defined Renaming the form’s file will rename the form  An application’s initial form is determined in the Main function of the Program class Also set in project properties

15 Modal vs. Modeless  “Modeless” windows do not restrict access to other windows/forms An application’s main window/form is typically modeless  “Modal” windows restrict access to other windows/forms Commonly referred to as “dialog boxes” Access to a “parent” form is blocked File | Open...

16 Modal Forms  Modal forms typically have a certain visual appearance FormBorderStyle ControlBox, MaximizeBox, MinimizeBox  Modal forms are displayed with a different method Show() vs. ShowDialog()  Modal forms communicate information to a parent form Form.Tag and Form.DialogResult Button.DialogResult

17 Simple Messages  MessageBox is a special modal form MessageBoxButtons MessageBoxIcon MessageBoxDefaultButton DialogResult  Used for alerting the user or requesting simple feedback MessageBox.Show(...);

18 Closing a Form  What happens when we close a form? FormClosing event  What can we do when a form closes? Prompt before closing a form Prevent the form from closing ○ FormClosingEventArgs.Cancel

19 A Simple Example  First form contains a Label for a name and an “Edit...” Button  Second form contains a TextBox with a name and OK and Cancel Buttons  The name should be passed into and out of the second form  The name should update on the first form when OK is clicked on the second form  The second form should confirm before exiting, but only if the name was changed

20

21 Debugging Windows  Debug > Windows > Locals Variables scoped to the current method  Debug > Windows > Autos Variables from current and previous statements  Debug > Windows > Watch  View and edit any value in the debugger  Debug > Windows > Immediate Evaluate expressions, call methods

22 Call Heirarchy  View > Call Heirarchy View all calls to and from any method

23 Output Window  Debug > Windows > Output Console.WriteLine();

24 Edit and Continue  Some changes can be made while debugging  Visual Studio will incorporate the changes as you debug the application

25 Debugging Options  Tools > Options Debugging  Debug > Exceptions When thrown When unhandled

26 Debug and Release Builds  Debug versions of an application contain additional information for tracking down problems  An assembly is built as either a debug or release version

27 Debug and Trace Info  System.Diagnostics.Trace Release and debug builds  System.Diagnostics.Debug Only debug builds  Logging execution information WriteLine AutoFlush, IndentSize, etc.  Confirming assumptions Assert

28 Additional Help  MSDN Tracing and Instrumenting Applications http://msdn.microsoft.com/en- us/library/zs6s4h68(v=vs.110).aspx http://msdn.microsoft.com/en- us/library/zs6s4h68(v=vs.110).aspx

29

30 Classes  Fields (data members)  Constructors (initialization)  Methods  Properties  Practice the principle of encapsulation Implementation of an object is encapsulated within the class How does a Gradebook object calculate averages? ○ It shouldn’t matter

31 Tiered Architecture  Presentation layer Forms  Middle layer (business logic) Business rules, calculations, special logic ○ Should a customer receive special rewards? ○ What is the local sales tax in Overland Park?  Database layer Access to physical storage ○ MySQL, Oracle?

32 Namespaces  Partition classes to group functionality  Specify classes using fully qualified name, or use the namespace within a.cs file

33 StudentGradeBook Class  Create a StudentGradeBook class  The grade book should store up to ten homework grades and four test grades  Add a methods to insert test and homework grades  Add a method to clear all grades  Add a property to return a final average (based on 80% tests and 20% homework)

34 StatsCalculator Example  Create a StatsCalculator class  Create a method for adding numeric values to the StatsCalculator  Create properties that will return: Total number of values Sum of values Average of values Minimum and maximum values  Create a method that will clear the calculator

35 Class Summary  Fields can be readonly  Control access with public/private  Initialize through constructor or object initializers  Properties have get and set blocks Read/write, read-only, write-only Auto-implemented  Methods can be overloaded  Members can be static

36 Member Variable Defaults  Numeric types = 0  Boolean = false  Char = 0  Object = null  Date = 01/01/0001 @ 12:00am

37 Class vs. Struct  Difference between reference and value types  Class requires “new”, struct does not

38 Suggested Practice  Exercise 12-1, p. 391

39 Start thinking about what classes might be used to model objects in the type of applications you will be writing. Are there any questions about objects you might be trying to model?


Download ppt "Neal Stublen Tonight’s Agenda  More form controls  Multi-form projects  Application debugging  Object-oriented programming and."

Similar presentations


Ads by Google