SlideShare a Scribd company logo
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 1
Chapter 3
How to code and test a
Windows Forms
application
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 2
A form object and its ten control objects
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 3
Class and object concepts
• An object is a self-contained unit that combines code and data.
Two examples of objects are forms and controls.
• A class is the code that defines the characteristics of an object.
You can think of a class as a template for an object.
• An object is an instance of a class, and the process of creating an
object from a class is called instantiation.
• More than one object instance can be created from a single class.
Then, each object has the same characteristics.
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 4
Property, method, and event concepts
• Properties define the characteristics of an object and the data
associated with an object.
• Methods are the operations that an object can perform.
• Events are signals sent by an object to the application telling it
that something has happened that can be responded to.
• Properties, methods, and events can be referred to as members of
an object.
• If you instantiate two or more instances of the same class, all of
the objects have the same properties, methods, and events.
However, the values assigned to the properties can vary from one
instance to another.
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 5
Objects and forms
• When you use the Form Designer, Visual Studio automatically
generates C# code that creates a new class based on the Form
class. Then, when you run the project, a form object is instantiated
from the new class.
• When you add a control to a form, Visual Studio automatically
generates C# code in the class for the form that instantiates a
control object from the appropriate class and sets the control’s
default properties.
• When you move and size a control, Visual Studio automatically
sets the properties that specify the location and size of the control.
Slide 6
Detour – How the IDE Creates Event Handlers
• Double click on the “Exit” button to get into the code editor.
• Do you see an event handler for clicking on the “Calculate”
button yet?
• Double click on the “Calculate” button
• Where the heck did this new code come from?
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 7
A member list that’s displayed in the Code Editor
window
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 8
The syntax for referring to a member of a class or
object
ClassName.MemberName
objectName.MemberName
Statements that refer to properties
txtTotal.Text = "10"; Assigns a string holding the number
10 to the Text property of the text box
named txtTotal.
txtTotal.ReadOnly = true; Assigns the true value to the
ReadOnly property of the text box
named txtTotal so the user can’t
change its contents.
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 9
Statements that refer to methods
txtMonthlyInvestment.Focus(); Uses the Focus method to move the
focus to the text box named
txtMonthlyInvestment.
this.Close(); Uses the Close method to close the
form that contains the statement.
Here, this is a keyword that is used to
refer to the current instance of the
class.
Code that refers to an event
btnExit.Click Refers to the Click event of a button
named btnExit.
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 10
How to enter member names when working in the
Code Editor window
1. To display a list of the available members for a class or an object,
type the class or object name followed by a period (called a dot
operator, or just dot).
2. Type one or more letters of the member name, and the Code Editor
will select the first entry in the list that matches those letters. Or you
can scroll down the list to select the member you want.
3. Press the Tab or Enter key to insert the member into your code.
Note
• If a member list isn’t displayed, select the ToolsOptions
command to display the Options dialog box. Then, expand the
Text Editor group, select the C# category, and check the Auto list
members and Parameters information boxes.
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 11
Event: The user clicks the Exit button
Wiring: The application determines what method to
execute
this.btnExit.Click += new
System.EventHandler(this.btnExit_Click);
Response: The method for the Click event of the Exit
button is executed
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
Wiring is hidden for a
reason but we can
find it if we want!
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 12
Common control events
Event Occurs when…
Click …the user clicks the control.
DoubleClick …the user double-clicks the control.
Enter …the focus is moved to the control.
Leave …the focus is moved from the control.
Common form events
Event Occurs when…
Load …the form is loaded into memory.
Closing …the form is closing.
Closed …the form is closed.
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 13
How an application responds to events
• Windows applications work by responding to events that occur on
objects.
• To indicate how an application should respond to an event, you
code an event handler, which is a special type of method that
handles the event.
• To connect the event handler to the event, Visual Studio
automatically generates a statement that wires the event to the
event handler. This is known as event wiring.
• An event can be an action that’s initiated by the user like the Click
event, or it can be an action initiated by program code like the
Closed event.
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 14
The method that handles the Click event of the
Calculate button
Object Event
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 15
How to handle the Click event of a button
1. In the Form Designer, double-click the control. This opens the Code
Editor, generates the declaration for the method that handles the
event, and places the cursor within this declaration.
2. Type the C# code between the opening brace ({) and the closing
brace (}) of the method declaration.
3. When you are finished writing code, you can return to the Form
Designer by clicking the View Designer button in the Solution
Explorer window.
How to handle the Load event for a form
• Follow the procedure above, but double-click the form itself.
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 16
The completion list that’s displayed when you
enter a letter at the beginning of a line of code
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 17
The completion list that’s displayed as you enter
code within a statement
Business Rules
• Assume discount = 0%
• If the Subtotal is $500 or more then the
discount = 20%
• If the Subtotal is $250 or more but less than
$500 then the discount = 15%
• If the Subtotal is $100 or more but less than
$250 then the discount = 10%
• Go through a few examples by hand of
calculating the discount percent, discount
amount, and total Slide 18
Slide 19
Subtotal  ___________
Discount Percentage  _______ >= $500 – 20%
$250-$499.99 – 15%
$100-$249.99 – 10%
Discount Amount  Subtotal X Discount Percentage
_______X_________________
Total  Subtotal – Discount Amount
_______ - ______________
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 20
The event handlers for the Invoice Total form
private void btnCalculate_Click(object sender,
System.EventArgs e)
{
decimal subtotal = Convert.ToDecimal(txtSubtotal.Text);
decimal discountPercent = 0m;
if (subtotal >= 500)
{
discountPercent = .2m;
}
else if (subtotal >= 250 && subtotal < 500)
{
discountPercent = .15m;
}
else if (subtotal >= 100 && subtotal < 250)
{
discountPercent = .1m;
}
decimal discountAmount = subtotal * discountPercent;
decimal invoiceTotal = subtotal - discountAmount;
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 21
The event handlers for the Invoice Total form
(continued)
txtDiscountPercent.Text
= discountPercent.ToString("p1");
txtDiscountAmount.Text = discountAmount.ToString("c");
txtTotal.Text = invoiceTotal.ToString("c");
txtSubtotal.Focus();
}
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 22
Coding rules
• Use spaces to separate the words in each statement.
• Use exact capitalization for all keywords, class names, object
names, variable names, etc.
• End each statement with a semicolon.
• Each block of code must be enclosed in braces ({}). That
includes the block of code that defines the body of a method.
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 23
The Code Editor and Error List windows with
syntax errors displayed
Slide 24
How to detect and correct syntax errors
• Visual Studio checks the syntax of C# code as you enter it. If a
syntax error is detected, it’s highlighted with a wavy underline
in the Code Editor window, and you can place the mouse
pointer over it to display a description of the error.
• If the Task List window is open, all of the syntax errors (or build
errors) are listed in that window. Then, you can double-click on
any error to take you to its location in the Code Editor window.
When you correct the error, it’s removed from the task list.
• By default, the Task List window is displayed when you build
an application that contains a syntax error. To open this window
and display the syntax errors before building the application, use
the ViewOther WindowsTask List command.
• Visual Studio doesn’t detect some syntax errors until the project
is built. As a result, you may encounter more syntax errors when
you build and run the project.
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 25
A method written in a less readable style
private void btnCalculate_Click(object sender, System.EventArgs e){
decimal subtotal=Convert.ToDecimal(txtSubtotal.Text);
decimal discountPercent=0m;
if (subtotal>=500) discountPercent=.2m;
else if (subtotal>=250&&subtotal<500) discountPercent=.15m;
else if (subtotal>=100&&subtotal<250) discountPercent=.1m;
decimal discountAmount=subtotal*discountPercent;
decimal invoiceTotal=subtotal-discountAmount;
txtDiscountPercent.Text=discountPercent.ToString("p1");
txtDiscountAmount.Text=discountAmount.ToString("c");
txtTotal.Text=invoiceTotal.ToString("c");txtSubtotal.Focus();}
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 26
A method written in a readable style
private void btnCalculate_Click(object sender,
System.EventArgs e)
{
decimal subtotal = Convert.ToDecimal(txtSubtotal.Text);
decimal discountPercent = 0m;
if (subtotal >= 500)
{
discountPercent = .2m;
}
else if (subtotal >= 250 && subtotal < 500)
{
discountPercent = .15m;
}
else if (subtotal >= 100 && subtotal < 250)
{
discountPercent = .1m;
}
decimal discountAmount = subtotal * discountPercent;
decimal invoiceTotal = subtotal - discountAmount;
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 27
A method written in a readable style (continued)
txtDiscountPercent.Text
= discountPercent.ToString("p1");
txtDiscountAmount.Text = discountAmount.ToString("c");
txtTotal.Text = invoiceTotal.ToString("c");
txtSubtotal.Focus();
}
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 28
Coding recommendations
• Use indentation and extra spaces to align statements and blocks
of code so they reflect the structure of the program.
• Use spaces to separate the words, operators, and values in each
statement.
• Use blank lines before and after groups of related statements.
Note
• As you enter code in the Code Editor window, Visual Studio
automatically adjusts its formatting by default.
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 29
A method with comments
private void btnCalculate_Click(object sender, System.EventArgs e)
{
/***************************************
* this method calculates the total
* for an invoice depending on a
* discount that's based on the subtotal
****************************************/
// get the subtotal amount from the Subtotal text box
decimal subtotal = Convert.ToDecimal(txtSubtotal.Text);
// set the discountPercent variable based
// on the value of the subtotal variable
decimal discountPercent = 0m; // the m indicates a decimal value
if (subtotal >= 500)
{
discountPercent = .2m;
}
else if (subtotal >= 250 && subtotal < 500)
{
discountPercent = .15m;
}
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 30
A method with comments (continued)
else if (subtotal >= 100 && subtotal < 250)
{
discountPercent = .1m;
}
// calculate and assign the values for the
// discountAmount and invoiceTotal variables
decimal discountAmount = subtotal * discountPercent;
decimal invoiceTotal = subtotal - discountAmount;
// format the values and display them in their text boxes
txtDiscountPercent.Text // percent format
= discountPercent.ToString("p1"); // with 1 decimal place
txtDiscountAmount.Text
= discountAmount.ToString("c"); // currency format
txtTotal.Text
= invoiceTotal.ToString("c");
// move the focus to the Subtotal text box
txtSubtotal.Focus();
}
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 31
How to code comments
• Comments are used to help document what a program does and
what the code within it does.
• To code a single-line comment, type // before the comment. You
can use this technique to add a comment on its own line or to
add a comment at the end of a line.
• To code a delimited comment, type /* at the start of the comment
and */ at the end. You can also code asterisks to identify the
lines in the comment, but that isn’t necessary.
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 32
The Code Editor window and the Text Editor
toolbar
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 33
How to use the buttons of the Text Editor toolbar
• To display or hide the Text Editor toolbar, right-click in the
toolbar area and choose Text Editor from the shortcut menu.
• To comment or uncomment several lines of code, select the lines
and click the Comment or Uncomment button.
• During testing, you can comment out a line of code. That way,
you can test a new statement without deleting the old statement.
• To increase or decrease the indentation of several lines of code,
select the lines and click the Increase Indent or Decrease Indent
button. Or, press the Tab and Shift+Tab keys.
• To move quickly between lines of code, you can use the last eight
buttons on the Text Editor toolbar to set and move between
bookmarks.
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 34
How to collapse or expand regions of code
• If a region of code appears in the Code Editor with a minus sign
(-) next to it, you can click the minus sign to collapse the region
so just the first line is displayed.
• If a region of code appears in the Code Editor with a plus sign (+)
next to it, you can click the plus sign to expand the region so all of
it is displayed.
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 35
The Code Editor with enlarged text
and a highlighted variable
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 36
The default list of Visual C# code snippets
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 37
A code snippet after it has been inserted
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 38
The bar that appears under a renamed variable
The menu that’s available from the bar
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 39
The Preview Changes dialog box
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 40
The Help Viewer
Slide 41
How to run a project
• To run a project, click the Start button in the Standard toolbar,
select the DebugStart menu command, or press the F5 key.
This causes Visual Studio to build the project and create an
assembly.
• If no build errors are detected, the assembly is run so the
project’s form is displayed over the IDE.
• If build errors are detected, they’re listed in the Task List
window and a dialog box asks whether you want to run the
project even though there were build errors. Click No to return
to the Code Editor.
• To locate a statement in error, you can double-click on the error
description in the Task List window. After you’ve corrected all
the errors, run the project again to rebuild it and clear the errors.
• To build a project without running it, select the BuildBuild
project name command.
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 42
The form displayed when you run the Invoice
Total project
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 43
The Exception Assistant that’s displayed
when a runtime error occurs
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 44
How to test a project
1. Test the user interface. Visually check all the controls to make
sure they are displayed properly with the correct text. Use the
Tab key to make sure the tab order is set correctly, verify that the
access keys work right, and make sure that the Enter and Esc
keys work properly.
2. Test valid input data. For example, enter data that you would
expect a user to enter.
3. Test invalid data or unexpected user actions. For example, leave
required fields blank, enter text data into numeric input fields,
and use negative numbers where they are not appropriate. Try
everything you can think of to make the application fail.
Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 45
How a project looks in break mode
Slide 46
How to debug runtime errors
• When an application ends with a runtime error, you need to fix
the error. This is commonly referred to as debugging, and the
error is commonly referred to as a bug.
• If you click the Break button in the dialog box for a runtime
error, Visual Studio displays the Code Editor window and
highlights the statement that caused the exception.
• When a program enters break mode, the debugging windows
and the Debug and Debug Location toolbars are displayed.
• In break mode, you can display the value of a variable or
property in a data tip by positioning the mouse pointer over it.
• To exit break mode and end the application, click the Stop
Debugging button in the Debug toolbar.
• To enter break mode any time that an application is running,
click the Break All button in the Debug toolbar. This is useful if
you need to stop a program that’s caught in a loop.
Slide 47
In-Class Activity
• Can you
– Code the “Exit” button
– Code the “Calculate..” to
• Access txtNumericGrade.Text
• Convert it to a decimal and store it in a variable
• Add 10 to this variable
• Convert this into a string and store it in the Text property of
lblLetterGrade
– Yes, I know this is a silly thing but I just want to get
you accessing & working with the Text property of
controls
Text box
Label
Slide 48
In-Class Activity
• Can you
– Code the “Exit” button
– Code the “Calculate..” button to
• Access txtOrderTotal.Text
• Convert it to a decimal and store it in a variable
• Add 10 to this variable
• Convert this into a string and store it in the Text property of
txtGrandTotal
– Yes, I know this is a silly thing but I just want to get
you accessing & working with the Text property of
controls
Text boxes
Read Only
Text Boxes
Slide 49
In-Class Activity
• Can you
– Code the “Exit” button
– Code the “Project..” button to
• Access txtNumberOfStudentsToday.Text
• Convert it to a decimal and store it in a variable
• Double this number
• Convert this into a string and store it in the Text property of
txtNumberOfProjectedStudents
– Yes, I know this is a silly thing but I just want to get
you accessing & working with the Text property of
controls
Text boxes
Read Only
Text Box
Slide 50
In-Class Activity
• Can you
– Code the “Exit” button
– Code the “Convert..” button to
• Access txtAlphanumericNumber.Text
• Store it in text property of txtNumericOnly
– Yes, I know this is a silly thing but I just want
to get you accessing & working with the Text
property of controls

More Related Content

What's hot

C# Tutorial MSM_Murach chapter-09-slides
C# Tutorial MSM_Murach chapter-09-slidesC# Tutorial MSM_Murach chapter-09-slides
C# Tutorial MSM_Murach chapter-09-slides
Sami Mut
 
C# Tutorial MSM_Murach chapter-18-slides
C# Tutorial MSM_Murach chapter-18-slidesC# Tutorial MSM_Murach chapter-18-slides
C# Tutorial MSM_Murach chapter-18-slides
Sami Mut
 
C# Tutorial MSM_Murach chapter-14-slides
C# Tutorial MSM_Murach chapter-14-slidesC# Tutorial MSM_Murach chapter-14-slides
C# Tutorial MSM_Murach chapter-14-slides
Sami Mut
 
C# Tutorial MSM_Murach chapter-11-slides
C# Tutorial MSM_Murach chapter-11-slidesC# Tutorial MSM_Murach chapter-11-slides
C# Tutorial MSM_Murach chapter-11-slides
Sami Mut
 
C# Tutorial MSM_Murach chapter-01-slides
C# Tutorial MSM_Murach chapter-01-slidesC# Tutorial MSM_Murach chapter-01-slides
C# Tutorial MSM_Murach chapter-01-slides
Sami Mut
 
C# Tutorial MSM_Murach chapter-07-slides
C# Tutorial MSM_Murach chapter-07-slidesC# Tutorial MSM_Murach chapter-07-slides
C# Tutorial MSM_Murach chapter-07-slides
Sami Mut
 
C# Tutorial MSM_Murach chapter-23-slides
C# Tutorial MSM_Murach chapter-23-slidesC# Tutorial MSM_Murach chapter-23-slides
C# Tutorial MSM_Murach chapter-23-slides
Sami Mut
 
C# Tutorial MSM_Murach chapter-22-slides
C# Tutorial MSM_Murach chapter-22-slidesC# Tutorial MSM_Murach chapter-22-slides
C# Tutorial MSM_Murach chapter-22-slides
Sami Mut
 
C# Tutorial MSM_Murach chapter-06-slides
C# Tutorial MSM_Murach chapter-06-slidesC# Tutorial MSM_Murach chapter-06-slides
C# Tutorial MSM_Murach chapter-06-slides
Sami Mut
 
C# Tutorial MSM_Murach chapter-08-slides
C# Tutorial MSM_Murach chapter-08-slidesC# Tutorial MSM_Murach chapter-08-slides
C# Tutorial MSM_Murach chapter-08-slides
Sami Mut
 
C# Tutorial MSM_Murach chapter-16-slides
C# Tutorial MSM_Murach chapter-16-slidesC# Tutorial MSM_Murach chapter-16-slides
C# Tutorial MSM_Murach chapter-16-slides
Sami Mut
 
C# Tutorial MSM_Murach chapter-05-slides
C# Tutorial MSM_Murach chapter-05-slidesC# Tutorial MSM_Murach chapter-05-slides
C# Tutorial MSM_Murach chapter-05-slides
Sami Mut
 
C# Tutorial MSM_Murach chapter-02-slides
C# Tutorial MSM_Murach chapter-02-slidesC# Tutorial MSM_Murach chapter-02-slides
C# Tutorial MSM_Murach chapter-02-slides
Sami Mut
 
C# Tutorial MSM_Murach chapter-17-slides
C# Tutorial MSM_Murach chapter-17-slidesC# Tutorial MSM_Murach chapter-17-slides
C# Tutorial MSM_Murach chapter-17-slides
Sami Mut
 
C# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slidesC# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slides
Sami Mut
 
C# Tutorial MSM_Murach chapter-04-slides
C# Tutorial MSM_Murach chapter-04-slidesC# Tutorial MSM_Murach chapter-04-slides
C# Tutorial MSM_Murach chapter-04-slides
Sami Mut
 
Intake 38 9
Intake 38 9Intake 38 9
Intake 38 9
Mahmoud Ouf
 
Intake 38 8
Intake 38 8Intake 38 8
Intake 38 8
Mahmoud Ouf
 
Intake 37 9
Intake 37 9Intake 37 9
Intake 37 9
Mahmoud Ouf
 
Autocad excel vba
Autocad excel vbaAutocad excel vba
Autocad excel vbarjg_vijay
 

What's hot (20)

C# Tutorial MSM_Murach chapter-09-slides
C# Tutorial MSM_Murach chapter-09-slidesC# Tutorial MSM_Murach chapter-09-slides
C# Tutorial MSM_Murach chapter-09-slides
 
C# Tutorial MSM_Murach chapter-18-slides
C# Tutorial MSM_Murach chapter-18-slidesC# Tutorial MSM_Murach chapter-18-slides
C# Tutorial MSM_Murach chapter-18-slides
 
C# Tutorial MSM_Murach chapter-14-slides
C# Tutorial MSM_Murach chapter-14-slidesC# Tutorial MSM_Murach chapter-14-slides
C# Tutorial MSM_Murach chapter-14-slides
 
C# Tutorial MSM_Murach chapter-11-slides
C# Tutorial MSM_Murach chapter-11-slidesC# Tutorial MSM_Murach chapter-11-slides
C# Tutorial MSM_Murach chapter-11-slides
 
C# Tutorial MSM_Murach chapter-01-slides
C# Tutorial MSM_Murach chapter-01-slidesC# Tutorial MSM_Murach chapter-01-slides
C# Tutorial MSM_Murach chapter-01-slides
 
C# Tutorial MSM_Murach chapter-07-slides
C# Tutorial MSM_Murach chapter-07-slidesC# Tutorial MSM_Murach chapter-07-slides
C# Tutorial MSM_Murach chapter-07-slides
 
C# Tutorial MSM_Murach chapter-23-slides
C# Tutorial MSM_Murach chapter-23-slidesC# Tutorial MSM_Murach chapter-23-slides
C# Tutorial MSM_Murach chapter-23-slides
 
C# Tutorial MSM_Murach chapter-22-slides
C# Tutorial MSM_Murach chapter-22-slidesC# Tutorial MSM_Murach chapter-22-slides
C# Tutorial MSM_Murach chapter-22-slides
 
C# Tutorial MSM_Murach chapter-06-slides
C# Tutorial MSM_Murach chapter-06-slidesC# Tutorial MSM_Murach chapter-06-slides
C# Tutorial MSM_Murach chapter-06-slides
 
C# Tutorial MSM_Murach chapter-08-slides
C# Tutorial MSM_Murach chapter-08-slidesC# Tutorial MSM_Murach chapter-08-slides
C# Tutorial MSM_Murach chapter-08-slides
 
C# Tutorial MSM_Murach chapter-16-slides
C# Tutorial MSM_Murach chapter-16-slidesC# Tutorial MSM_Murach chapter-16-slides
C# Tutorial MSM_Murach chapter-16-slides
 
C# Tutorial MSM_Murach chapter-05-slides
C# Tutorial MSM_Murach chapter-05-slidesC# Tutorial MSM_Murach chapter-05-slides
C# Tutorial MSM_Murach chapter-05-slides
 
C# Tutorial MSM_Murach chapter-02-slides
C# Tutorial MSM_Murach chapter-02-slidesC# Tutorial MSM_Murach chapter-02-slides
C# Tutorial MSM_Murach chapter-02-slides
 
C# Tutorial MSM_Murach chapter-17-slides
C# Tutorial MSM_Murach chapter-17-slidesC# Tutorial MSM_Murach chapter-17-slides
C# Tutorial MSM_Murach chapter-17-slides
 
C# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slidesC# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slides
 
C# Tutorial MSM_Murach chapter-04-slides
C# Tutorial MSM_Murach chapter-04-slidesC# Tutorial MSM_Murach chapter-04-slides
C# Tutorial MSM_Murach chapter-04-slides
 
Intake 38 9
Intake 38 9Intake 38 9
Intake 38 9
 
Intake 38 8
Intake 38 8Intake 38 8
Intake 38 8
 
Intake 37 9
Intake 37 9Intake 37 9
Intake 37 9
 
Autocad excel vba
Autocad excel vbaAutocad excel vba
Autocad excel vba
 

Similar to C# Tutorial MSM_Murach chapter-03-slides

Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
JOSEPHINEA6
 
Csc153 chapter 03
Csc153 chapter 03Csc153 chapter 03
Csc153 chapter 03PCC
 
COM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptxCOM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptx
AnasYunusa
 
Software engineering modeling lab lectures
Software engineering modeling lab lecturesSoftware engineering modeling lab lectures
Software engineering modeling lab lectures
marwaeng
 
Intellect_Integration_-_Web_Integration_Methods.pdf
Intellect_Integration_-_Web_Integration_Methods.pdfIntellect_Integration_-_Web_Integration_Methods.pdf
Intellect_Integration_-_Web_Integration_Methods.pdf
Modern Modular NY.
 
Access tips access and sql part 4 building select queries on-the-fly
Access tips  access and sql part 4  building select queries on-the-flyAccess tips  access and sql part 4  building select queries on-the-fly
Access tips access and sql part 4 building select queries on-the-fly
quest2900
 
Lect02 Introducing Programming.ppt
Lect02 Introducing Programming.pptLect02 Introducing Programming.ppt
Lect02 Introducing Programming.ppt
NourhanTarek23
 
Visual C# 2010
Visual C# 2010Visual C# 2010
Visual C# 2010
Ali Mattash
 
Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web
MahmoudOHassouna
 
Access tips access and sql part 6 dynamic reports
Access tips  access and sql part 6  dynamic reportsAccess tips  access and sql part 6  dynamic reports
Access tips access and sql part 6 dynamic reports
quest2900
 
Chapter 08
Chapter 08Chapter 08
Chapter 08llmeade
 
Vb.net and .Net Framework
Vb.net and .Net FrameworkVb.net and .Net Framework
Vb.net and .Net Framework
SHIVANGICHAURASIYA
 
CIS 170 Life of the Mind/newtonhelp.com   
CIS 170 Life of the Mind/newtonhelp.com   CIS 170 Life of the Mind/newtonhelp.com   
CIS 170 Life of the Mind/newtonhelp.com   
llflowe
 
CIS 170 Imagine Your Future/newtonhelp.com   
CIS 170 Imagine Your Future/newtonhelp.com   CIS 170 Imagine Your Future/newtonhelp.com   
CIS 170 Imagine Your Future/newtonhelp.com   
bellflower42
 
Cis 170 Extraordinary Success/newtonhelp.com
Cis 170 Extraordinary Success/newtonhelp.com  Cis 170 Extraordinary Success/newtonhelp.com
Cis 170 Extraordinary Success/newtonhelp.com
amaranthbeg143
 
Diving into VS 2015 Day1
Diving into VS 2015 Day1Diving into VS 2015 Day1
Diving into VS 2015 Day1Akhil Mittal
 
CIS 170 Focus Dreams/newtonhelp.com
CIS 170 Focus Dreams/newtonhelp.comCIS 170 Focus Dreams/newtonhelp.com
CIS 170 Focus Dreams/newtonhelp.com
bellflower82
 

Similar to C# Tutorial MSM_Murach chapter-03-slides (20)

Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
Csc153 chapter 03
Csc153 chapter 03Csc153 chapter 03
Csc153 chapter 03
 
COM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptxCOM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptx
 
Software engineering modeling lab lectures
Software engineering modeling lab lecturesSoftware engineering modeling lab lectures
Software engineering modeling lab lectures
 
Intellect_Integration_-_Web_Integration_Methods.pdf
Intellect_Integration_-_Web_Integration_Methods.pdfIntellect_Integration_-_Web_Integration_Methods.pdf
Intellect_Integration_-_Web_Integration_Methods.pdf
 
Access tips access and sql part 4 building select queries on-the-fly
Access tips  access and sql part 4  building select queries on-the-flyAccess tips  access and sql part 4  building select queries on-the-fly
Access tips access and sql part 4 building select queries on-the-fly
 
Lect02 Introducing Programming.ppt
Lect02 Introducing Programming.pptLect02 Introducing Programming.ppt
Lect02 Introducing Programming.ppt
 
Visual C# 2010
Visual C# 2010Visual C# 2010
Visual C# 2010
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web
 
Access tips access and sql part 6 dynamic reports
Access tips  access and sql part 6  dynamic reportsAccess tips  access and sql part 6  dynamic reports
Access tips access and sql part 6 dynamic reports
 
Chapter 08
Chapter 08Chapter 08
Chapter 08
 
Vb.net and .Net Framework
Vb.net and .Net FrameworkVb.net and .Net Framework
Vb.net and .Net Framework
 
CIS 170 Life of the Mind/newtonhelp.com   
CIS 170 Life of the Mind/newtonhelp.com   CIS 170 Life of the Mind/newtonhelp.com   
CIS 170 Life of the Mind/newtonhelp.com   
 
CIS 170 Imagine Your Future/newtonhelp.com   
CIS 170 Imagine Your Future/newtonhelp.com   CIS 170 Imagine Your Future/newtonhelp.com   
CIS 170 Imagine Your Future/newtonhelp.com   
 
Ch01
Ch01Ch01
Ch01
 
Cis 170 Extraordinary Success/newtonhelp.com
Cis 170 Extraordinary Success/newtonhelp.com  Cis 170 Extraordinary Success/newtonhelp.com
Cis 170 Extraordinary Success/newtonhelp.com
 
Mca 504 dotnet_unit5
Mca 504 dotnet_unit5Mca 504 dotnet_unit5
Mca 504 dotnet_unit5
 
Diving into VS 2015 Day1
Diving into VS 2015 Day1Diving into VS 2015 Day1
Diving into VS 2015 Day1
 
CIS 170 Focus Dreams/newtonhelp.com
CIS 170 Focus Dreams/newtonhelp.comCIS 170 Focus Dreams/newtonhelp.com
CIS 170 Focus Dreams/newtonhelp.com
 

More from Sami Mut

MSM_Time
MSM_TimeMSM_Time
MSM_Time
Sami Mut
 
chapter 5 Java at rupp cambodia
chapter 5 Java at rupp cambodiachapter 5 Java at rupp cambodia
chapter 5 Java at rupp cambodia
Sami Mut
 
chapter 2 Java at rupp cambodia
chapter 2 Java at rupp cambodiachapter 2 Java at rupp cambodia
chapter 2 Java at rupp cambodia
Sami Mut
 
chapter 3 Java at rupp cambodia
chapter 3 Java at rupp cambodiachapter 3 Java at rupp cambodia
chapter 3 Java at rupp cambodia
Sami Mut
 
chapter 2 Java at rupp cambodia
chapter 2 Java at rupp cambodiachapter 2 Java at rupp cambodia
chapter 2 Java at rupp cambodia
Sami Mut
 
chapter 1 Java at rupp cambodia
chapter 1 Java at rupp cambodiachapter 1 Java at rupp cambodia
chapter 1 Java at rupp cambodia
Sami Mut
 

More from Sami Mut (6)

MSM_Time
MSM_TimeMSM_Time
MSM_Time
 
chapter 5 Java at rupp cambodia
chapter 5 Java at rupp cambodiachapter 5 Java at rupp cambodia
chapter 5 Java at rupp cambodia
 
chapter 2 Java at rupp cambodia
chapter 2 Java at rupp cambodiachapter 2 Java at rupp cambodia
chapter 2 Java at rupp cambodia
 
chapter 3 Java at rupp cambodia
chapter 3 Java at rupp cambodiachapter 3 Java at rupp cambodia
chapter 3 Java at rupp cambodia
 
chapter 2 Java at rupp cambodia
chapter 2 Java at rupp cambodiachapter 2 Java at rupp cambodia
chapter 2 Java at rupp cambodia
 
chapter 1 Java at rupp cambodia
chapter 1 Java at rupp cambodiachapter 1 Java at rupp cambodia
chapter 1 Java at rupp cambodia
 

Recently uploaded

Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 

Recently uploaded (20)

Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 

C# Tutorial MSM_Murach chapter-03-slides

  • 1. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 1 Chapter 3 How to code and test a Windows Forms application
  • 2. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 2 A form object and its ten control objects
  • 3. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 3 Class and object concepts • An object is a self-contained unit that combines code and data. Two examples of objects are forms and controls. • A class is the code that defines the characteristics of an object. You can think of a class as a template for an object. • An object is an instance of a class, and the process of creating an object from a class is called instantiation. • More than one object instance can be created from a single class. Then, each object has the same characteristics.
  • 4. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 4 Property, method, and event concepts • Properties define the characteristics of an object and the data associated with an object. • Methods are the operations that an object can perform. • Events are signals sent by an object to the application telling it that something has happened that can be responded to. • Properties, methods, and events can be referred to as members of an object. • If you instantiate two or more instances of the same class, all of the objects have the same properties, methods, and events. However, the values assigned to the properties can vary from one instance to another.
  • 5. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 5 Objects and forms • When you use the Form Designer, Visual Studio automatically generates C# code that creates a new class based on the Form class. Then, when you run the project, a form object is instantiated from the new class. • When you add a control to a form, Visual Studio automatically generates C# code in the class for the form that instantiates a control object from the appropriate class and sets the control’s default properties. • When you move and size a control, Visual Studio automatically sets the properties that specify the location and size of the control.
  • 6. Slide 6 Detour – How the IDE Creates Event Handlers • Double click on the “Exit” button to get into the code editor. • Do you see an event handler for clicking on the “Calculate” button yet? • Double click on the “Calculate” button • Where the heck did this new code come from?
  • 7. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 7 A member list that’s displayed in the Code Editor window
  • 8. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 8 The syntax for referring to a member of a class or object ClassName.MemberName objectName.MemberName Statements that refer to properties txtTotal.Text = "10"; Assigns a string holding the number 10 to the Text property of the text box named txtTotal. txtTotal.ReadOnly = true; Assigns the true value to the ReadOnly property of the text box named txtTotal so the user can’t change its contents.
  • 9. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 9 Statements that refer to methods txtMonthlyInvestment.Focus(); Uses the Focus method to move the focus to the text box named txtMonthlyInvestment. this.Close(); Uses the Close method to close the form that contains the statement. Here, this is a keyword that is used to refer to the current instance of the class. Code that refers to an event btnExit.Click Refers to the Click event of a button named btnExit.
  • 10. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 10 How to enter member names when working in the Code Editor window 1. To display a list of the available members for a class or an object, type the class or object name followed by a period (called a dot operator, or just dot). 2. Type one or more letters of the member name, and the Code Editor will select the first entry in the list that matches those letters. Or you can scroll down the list to select the member you want. 3. Press the Tab or Enter key to insert the member into your code. Note • If a member list isn’t displayed, select the ToolsOptions command to display the Options dialog box. Then, expand the Text Editor group, select the C# category, and check the Auto list members and Parameters information boxes.
  • 11. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 11 Event: The user clicks the Exit button Wiring: The application determines what method to execute this.btnExit.Click += new System.EventHandler(this.btnExit_Click); Response: The method for the Click event of the Exit button is executed private void btnExit_Click(object sender, System.EventArgs e) { this.Close(); } Wiring is hidden for a reason but we can find it if we want!
  • 12. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 12 Common control events Event Occurs when… Click …the user clicks the control. DoubleClick …the user double-clicks the control. Enter …the focus is moved to the control. Leave …the focus is moved from the control. Common form events Event Occurs when… Load …the form is loaded into memory. Closing …the form is closing. Closed …the form is closed.
  • 13. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 13 How an application responds to events • Windows applications work by responding to events that occur on objects. • To indicate how an application should respond to an event, you code an event handler, which is a special type of method that handles the event. • To connect the event handler to the event, Visual Studio automatically generates a statement that wires the event to the event handler. This is known as event wiring. • An event can be an action that’s initiated by the user like the Click event, or it can be an action initiated by program code like the Closed event.
  • 14. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 14 The method that handles the Click event of the Calculate button Object Event
  • 15. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 15 How to handle the Click event of a button 1. In the Form Designer, double-click the control. This opens the Code Editor, generates the declaration for the method that handles the event, and places the cursor within this declaration. 2. Type the C# code between the opening brace ({) and the closing brace (}) of the method declaration. 3. When you are finished writing code, you can return to the Form Designer by clicking the View Designer button in the Solution Explorer window. How to handle the Load event for a form • Follow the procedure above, but double-click the form itself.
  • 16. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 16 The completion list that’s displayed when you enter a letter at the beginning of a line of code
  • 17. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 17 The completion list that’s displayed as you enter code within a statement
  • 18. Business Rules • Assume discount = 0% • If the Subtotal is $500 or more then the discount = 20% • If the Subtotal is $250 or more but less than $500 then the discount = 15% • If the Subtotal is $100 or more but less than $250 then the discount = 10% • Go through a few examples by hand of calculating the discount percent, discount amount, and total Slide 18
  • 19. Slide 19 Subtotal  ___________ Discount Percentage  _______ >= $500 – 20% $250-$499.99 – 15% $100-$249.99 – 10% Discount Amount  Subtotal X Discount Percentage _______X_________________ Total  Subtotal – Discount Amount _______ - ______________
  • 20. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 20 The event handlers for the Invoice Total form private void btnCalculate_Click(object sender, System.EventArgs e) { decimal subtotal = Convert.ToDecimal(txtSubtotal.Text); decimal discountPercent = 0m; if (subtotal >= 500) { discountPercent = .2m; } else if (subtotal >= 250 && subtotal < 500) { discountPercent = .15m; } else if (subtotal >= 100 && subtotal < 250) { discountPercent = .1m; } decimal discountAmount = subtotal * discountPercent; decimal invoiceTotal = subtotal - discountAmount;
  • 21. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 21 The event handlers for the Invoice Total form (continued) txtDiscountPercent.Text = discountPercent.ToString("p1"); txtDiscountAmount.Text = discountAmount.ToString("c"); txtTotal.Text = invoiceTotal.ToString("c"); txtSubtotal.Focus(); } private void btnExit_Click(object sender, System.EventArgs e) { this.Close(); }
  • 22. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 22 Coding rules • Use spaces to separate the words in each statement. • Use exact capitalization for all keywords, class names, object names, variable names, etc. • End each statement with a semicolon. • Each block of code must be enclosed in braces ({}). That includes the block of code that defines the body of a method.
  • 23. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 23 The Code Editor and Error List windows with syntax errors displayed
  • 24. Slide 24 How to detect and correct syntax errors • Visual Studio checks the syntax of C# code as you enter it. If a syntax error is detected, it’s highlighted with a wavy underline in the Code Editor window, and you can place the mouse pointer over it to display a description of the error. • If the Task List window is open, all of the syntax errors (or build errors) are listed in that window. Then, you can double-click on any error to take you to its location in the Code Editor window. When you correct the error, it’s removed from the task list. • By default, the Task List window is displayed when you build an application that contains a syntax error. To open this window and display the syntax errors before building the application, use the ViewOther WindowsTask List command. • Visual Studio doesn’t detect some syntax errors until the project is built. As a result, you may encounter more syntax errors when you build and run the project.
  • 25. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 25 A method written in a less readable style private void btnCalculate_Click(object sender, System.EventArgs e){ decimal subtotal=Convert.ToDecimal(txtSubtotal.Text); decimal discountPercent=0m; if (subtotal>=500) discountPercent=.2m; else if (subtotal>=250&&subtotal<500) discountPercent=.15m; else if (subtotal>=100&&subtotal<250) discountPercent=.1m; decimal discountAmount=subtotal*discountPercent; decimal invoiceTotal=subtotal-discountAmount; txtDiscountPercent.Text=discountPercent.ToString("p1"); txtDiscountAmount.Text=discountAmount.ToString("c"); txtTotal.Text=invoiceTotal.ToString("c");txtSubtotal.Focus();}
  • 26. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 26 A method written in a readable style private void btnCalculate_Click(object sender, System.EventArgs e) { decimal subtotal = Convert.ToDecimal(txtSubtotal.Text); decimal discountPercent = 0m; if (subtotal >= 500) { discountPercent = .2m; } else if (subtotal >= 250 && subtotal < 500) { discountPercent = .15m; } else if (subtotal >= 100 && subtotal < 250) { discountPercent = .1m; } decimal discountAmount = subtotal * discountPercent; decimal invoiceTotal = subtotal - discountAmount;
  • 27. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 27 A method written in a readable style (continued) txtDiscountPercent.Text = discountPercent.ToString("p1"); txtDiscountAmount.Text = discountAmount.ToString("c"); txtTotal.Text = invoiceTotal.ToString("c"); txtSubtotal.Focus(); }
  • 28. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 28 Coding recommendations • Use indentation and extra spaces to align statements and blocks of code so they reflect the structure of the program. • Use spaces to separate the words, operators, and values in each statement. • Use blank lines before and after groups of related statements. Note • As you enter code in the Code Editor window, Visual Studio automatically adjusts its formatting by default.
  • 29. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 29 A method with comments private void btnCalculate_Click(object sender, System.EventArgs e) { /*************************************** * this method calculates the total * for an invoice depending on a * discount that's based on the subtotal ****************************************/ // get the subtotal amount from the Subtotal text box decimal subtotal = Convert.ToDecimal(txtSubtotal.Text); // set the discountPercent variable based // on the value of the subtotal variable decimal discountPercent = 0m; // the m indicates a decimal value if (subtotal >= 500) { discountPercent = .2m; } else if (subtotal >= 250 && subtotal < 500) { discountPercent = .15m; }
  • 30. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 30 A method with comments (continued) else if (subtotal >= 100 && subtotal < 250) { discountPercent = .1m; } // calculate and assign the values for the // discountAmount and invoiceTotal variables decimal discountAmount = subtotal * discountPercent; decimal invoiceTotal = subtotal - discountAmount; // format the values and display them in their text boxes txtDiscountPercent.Text // percent format = discountPercent.ToString("p1"); // with 1 decimal place txtDiscountAmount.Text = discountAmount.ToString("c"); // currency format txtTotal.Text = invoiceTotal.ToString("c"); // move the focus to the Subtotal text box txtSubtotal.Focus(); }
  • 31. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 31 How to code comments • Comments are used to help document what a program does and what the code within it does. • To code a single-line comment, type // before the comment. You can use this technique to add a comment on its own line or to add a comment at the end of a line. • To code a delimited comment, type /* at the start of the comment and */ at the end. You can also code asterisks to identify the lines in the comment, but that isn’t necessary.
  • 32. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 32 The Code Editor window and the Text Editor toolbar
  • 33. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 33 How to use the buttons of the Text Editor toolbar • To display or hide the Text Editor toolbar, right-click in the toolbar area and choose Text Editor from the shortcut menu. • To comment or uncomment several lines of code, select the lines and click the Comment or Uncomment button. • During testing, you can comment out a line of code. That way, you can test a new statement without deleting the old statement. • To increase or decrease the indentation of several lines of code, select the lines and click the Increase Indent or Decrease Indent button. Or, press the Tab and Shift+Tab keys. • To move quickly between lines of code, you can use the last eight buttons on the Text Editor toolbar to set and move between bookmarks.
  • 34. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 34 How to collapse or expand regions of code • If a region of code appears in the Code Editor with a minus sign (-) next to it, you can click the minus sign to collapse the region so just the first line is displayed. • If a region of code appears in the Code Editor with a plus sign (+) next to it, you can click the plus sign to expand the region so all of it is displayed.
  • 35. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 35 The Code Editor with enlarged text and a highlighted variable
  • 36. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 36 The default list of Visual C# code snippets
  • 37. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 37 A code snippet after it has been inserted
  • 38. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 38 The bar that appears under a renamed variable The menu that’s available from the bar
  • 39. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 39 The Preview Changes dialog box
  • 40. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 40 The Help Viewer
  • 41. Slide 41 How to run a project • To run a project, click the Start button in the Standard toolbar, select the DebugStart menu command, or press the F5 key. This causes Visual Studio to build the project and create an assembly. • If no build errors are detected, the assembly is run so the project’s form is displayed over the IDE. • If build errors are detected, they’re listed in the Task List window and a dialog box asks whether you want to run the project even though there were build errors. Click No to return to the Code Editor. • To locate a statement in error, you can double-click on the error description in the Task List window. After you’ve corrected all the errors, run the project again to rebuild it and clear the errors. • To build a project without running it, select the BuildBuild project name command.
  • 42. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 42 The form displayed when you run the Invoice Total project
  • 43. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 43 The Exception Assistant that’s displayed when a runtime error occurs
  • 44. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 44 How to test a project 1. Test the user interface. Visually check all the controls to make sure they are displayed properly with the correct text. Use the Tab key to make sure the tab order is set correctly, verify that the access keys work right, and make sure that the Enter and Esc keys work properly. 2. Test valid input data. For example, enter data that you would expect a user to enter. 3. Test invalid data or unexpected user actions. For example, leave required fields blank, enter text data into numeric input fields, and use negative numbers where they are not appropriate. Try everything you can think of to make the application fail.
  • 45. Murach’s C# 2010, C3 © 2010, Mike Murach & Associates, Inc. Slide 45 How a project looks in break mode
  • 46. Slide 46 How to debug runtime errors • When an application ends with a runtime error, you need to fix the error. This is commonly referred to as debugging, and the error is commonly referred to as a bug. • If you click the Break button in the dialog box for a runtime error, Visual Studio displays the Code Editor window and highlights the statement that caused the exception. • When a program enters break mode, the debugging windows and the Debug and Debug Location toolbars are displayed. • In break mode, you can display the value of a variable or property in a data tip by positioning the mouse pointer over it. • To exit break mode and end the application, click the Stop Debugging button in the Debug toolbar. • To enter break mode any time that an application is running, click the Break All button in the Debug toolbar. This is useful if you need to stop a program that’s caught in a loop.
  • 47. Slide 47 In-Class Activity • Can you – Code the “Exit” button – Code the “Calculate..” to • Access txtNumericGrade.Text • Convert it to a decimal and store it in a variable • Add 10 to this variable • Convert this into a string and store it in the Text property of lblLetterGrade – Yes, I know this is a silly thing but I just want to get you accessing & working with the Text property of controls Text box Label
  • 48. Slide 48 In-Class Activity • Can you – Code the “Exit” button – Code the “Calculate..” button to • Access txtOrderTotal.Text • Convert it to a decimal and store it in a variable • Add 10 to this variable • Convert this into a string and store it in the Text property of txtGrandTotal – Yes, I know this is a silly thing but I just want to get you accessing & working with the Text property of controls Text boxes Read Only Text Boxes
  • 49. Slide 49 In-Class Activity • Can you – Code the “Exit” button – Code the “Project..” button to • Access txtNumberOfStudentsToday.Text • Convert it to a decimal and store it in a variable • Double this number • Convert this into a string and store it in the Text property of txtNumberOfProjectedStudents – Yes, I know this is a silly thing but I just want to get you accessing & working with the Text property of controls Text boxes Read Only Text Box
  • 50. Slide 50 In-Class Activity • Can you – Code the “Exit” button – Code the “Convert..” button to • Access txtAlphanumericNumber.Text • Store it in text property of txtNumericOnly – Yes, I know this is a silly thing but I just want to get you accessing & working with the Text property of controls