introduction to windows programming - electrical...

68
C# Programming: From Problem Analysis to Program Design 1 Introduction to Windows Programming C# Programming: From Problem Analysis to Program Design 4th Edition 9

Upload: vuongdung

Post on 25-Aug-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 1

Introduction to

Windows

Programming

C# Programming: From Problem Analysis to Program Design

4th Edition

9

Page 2: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

2

Chapter Objectives

Page 3: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

3

Contrasting Windows and Console

Applications

Main()

Page 4: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 4

Graphical User Interfaces

Page 5: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

5

Windows Applications

• public class Form1 : Form

Page 6: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

6

Windows Applications (continued)

• Text

Main()

– Main() Program.cs

Run()

Page 7: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

using System.Windows.Forms; // Line 1

namespace Windows0

{

public class Form1 : Form // Line 2

{

public Form1( ) // Line 3

{

Text = "Simple Windows Application"; // Line 4

}

static void Main( )

{

InitializeComponent(); this.Text = "Simple Windows Application";

}

}

}

1

System.Windows.Forms

Form

Form1 winForm = new Form1( ); Application.Run(winForm);

2

3

4,5

Page 8: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

using System.Windows.Forms; namespace Lesson09Prep { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.Text = "Simple Windows Application"; } } }

1

System.Windows.Forms

Form

Form1 winForm = new Form1( ); Application.Run(winForm);

2

3

4,5

Windows Application - Example

Page 9: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

9

Windows Application (continued)

Generated

output

Page 10: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

10

Elements of Good Design

Page 11: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

11

Use Visual Studio to Create Windows-Based Applications

Windows Forms App

(.Net Framework )

Name

Figure 9-2 Visual Studio New Windows application

Select

File New

Project

Page 12: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

12

Windows-Based Applications

Properties

Window

Toolbox

Design View

Page 13: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

13

Windows-Based Apps

Toolbox

Page 14: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 14

Windows Forms

Page 15: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

15

Windows Form Properties

Properties Property value

Page 16: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

Windows Form Properties

C# Programming: From Problem Analysis to Program Design 16

Figure 9-6 Form events

Page 17: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

Windows Form Properties

(continued)

17

Page 18: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

Inspecting the Code Generated

by Visual Studio

18

Expand Form1.cs

node to reveal the

Form1.Designer.cs

file

Page 19: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

Inspecting the Code - Form1.cs

InitializeComponent( )

19

namespace MyFirstWindowsApp { partial class Form1 { /// <summary> /// ... #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.SuspendLayout(); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(629, 455); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion } }

Page 20: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

20

Windows Form Events

Form1.cs

Page 21: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

21

Windows Form Properties (continued)

Events button selected

Page 22: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

22

Windows Form – Closing Event

public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { MessageBox.Show("Bye - Hope you had fun!", "Leaving this app"); } } }

Page 23: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

23

Controls (continued)

Dots

indicate

other

classes

are

derived

from the

class

Figure 9-9 Control class hierarchy

Page 24: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

24

Properties of the Control Class

Table 9-2 Systems.Windows.Forms.Control class properties

Page 25: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

Properties of the Control Class

(continued)

25 Table 9-2 Systems.Windows.Forms.Control class properties

Page 26: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

Methods of the Control Class

26

Table 9-3 includes a

short list of some of the

many methods.

Explore MSDN for

more documentation

Page 27: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

Pizza App

27

Page 28: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

Pizza App – Form1 Desing

28

btnPlaceYourOrder btnCancelAndClear

lblSides

grpCheese

comSides Items (collection) None Breadsticks Cheesesticks Garlic knots Fries

grpCheese radNormal radDouble radNone

grpShape radRounded radSquared

grpToppings chkPepperoni chkMushroom chkOnions chkAnchovies

txtCustomerName txtPhone

Page 29: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

Pizza App – Form2

29

btnQuit

txtOderSummary

btnBack

Page 30: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

Pizza App – Form1.cs 1 of 3

30

namespace WindowsFormsApp { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void comSides_SelectedIndexChanged(object sender, EventArgs e) { string selectedItem = comSides.Items[comSides.SelectedIndex].ToString(); if (selectedItem == "None") { lblSides.Text = "Summary of sides: "; } else { lblSides.Text += selectedItem + ", "; } } private void btnPlaceOrder_Click(object sender, EventArgs e) { //this string holds all choices made string choices = ""; //(EXCLUSIVE) obtaining the pizza's shape if (radRounded.Checked) choices += "Rounded, "; else if (radSquared.Checked) choices += "Squared, ";

Page 31: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

Pizza App – Form1.cs 2 of 3

31

//(EXCLUSIVE) looking into cheese selection if (radCheeseNormal.Checked) choices += "Normal cheese, "; else if (radCheeseDouble.Checked) choices += "Double cheese, "; else if (radCheeseNone.Checked) choices += "No cheese, "; //(INCLUSIVE) collecting all toppings checked by the customer if (chkPepperoni.Checked) choices += "Pepperoni, "; if (chkMushroom.Checked) choices += "Mushroom, "; if (chkOnions.Checked) choices += "Onions, "; if (chkAnchovies.Checked) choices += "Anchovies, "; //(MULTIPLE) extracting Beverage elections from the CheckedListBox var itemList = chkListBeverage.CheckedItems; foreach (var item in itemList) { choices += item + ", "; } //obtaining customer's name and phone choices += "\n" + txtCustomerName.Text + " " + txtPhone.Text; MessageBox.Show(choices, "Quick Summary"); //call other form to display summary Form2 f2 = new Form2(choices, this); f2.ShowDialog(); //try f2.Show(); }

Page 32: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

Pizza App – Form1.cs 3 of 3

32

private void btnCancel_Click(object sender, EventArgs e) { //clear all side selections lblSides.Text = "Summary of sides: "; //clear all beverage selections for (int i = 0; i < chkListBeverage.Items.Count; i++) { chkListBeverage.SetItemCheckState(i, CheckState.Unchecked); } //individually, clear each topping option chkPepperoni.CheckState = CheckState.Unchecked; chkOnions.CheckState = CheckState.Unchecked; chkMushroom.CheckState = CheckState.Unchecked; chkAnchovies.CheckState = CheckState.Unchecked; } } }

Page 33: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

Pizza App – Form2.cs 1 of 1

33

namespace WindowsFormsApp { public partial class Form2 : Form { //this variable will be used to remember who called us Form1 form1Reference; public Form2() { InitializeComponent(); } //we added this constructor to accept the order's text and //a reference to the form that called us public Form2(string orderSummaryValue, Form1 callerRefValue) { InitializeComponent(); txtOrderSummary.Text = orderSummaryValue; form1Reference = callerRefValue; } private void btnBack_Click(object sender, EventArgs e) { //go back to our caller, close current form form1Reference.Show(); this.Close(); } private void btnQuit_Click(object sender, EventArgs e) { this.Close(); //closes current form Application.Exit(); //terminates application } } }

Page 34: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 34

Creating a TaxApp

Properties set for the Form

container

Table 9-4 TaxApp Form1 properties

Page 35: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 35

Creating a TaxApp Form

Figure 9-12 Formatting Label objects

Add Label

objects to

Form

object…

Use

options on

FORMAT

menu

Page 36: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 36

Adding Labels to TaxApp Form

Table 9-5 TaxApp label5 object properties

Add Label objects, then set

their properties using the

Properties window

(View Properties window)

Page 37: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 37

TextBox Objects

• Used to enter data or display text during run time

– Used for both input and output

• Instantiate object

TextBox textBoxName = new TextBox( );

• Add control to Form this.Controls.Add(TextBoxName);

• Interesting properties

– MultiLine, ScollBars, MaxLength, PasswordChar, CharacterCasing

Page 38: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 38

TextBox Objects (continued)

Table 9-6 TextBox properties

Page 39: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

TextBox Objects (continued)

C# Programming: From Problem Analysis to Program Design 39

Table 9-6 TextBox properties (continued)

Page 40: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 40

Adding TextBox Objects to

TaxApp Form Add TextBox objects,

then set their property

values

Table 9-7 TaxApp TextBox objects property changes

Page 41: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 41

Button

• Enables user to click button to perform task

– If button has event-handler method and is registered as

an event to which your program is planning to respond,

event-handler method is called automatically when

button clicked

• Button object’s properties, methods, and events

– Inherits from Control (Table 9-2 & 9-3, slides 31-33)

• Text, Enabled, Focused, TabIndex

Page 42: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 42

Adding Button Objects to

TaxApp Form

Add

Button

objects,

then set

their

property

values

Table 9-7 TaxApp button1 properties

Page 43: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 43

Adding Button

Objects to

TaxApp Form

(continued)

Figure 9-14 Events

Page 44: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 44

Adding Button Objects to

TaxApp Form (continued)

•When you double-click on event, an event-

handler method is created: private void btnCompute_Click(object

sender, System.EventArgs e)

{

}

•AND registers click event: this.btnCompute.Click +=

new System.EventHandler

(this.btnCompute_Click);

Page 45: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 45

Adding Button Objects to

TaxApp Form (continued) private void btnCompute_Click(object sender, System.EventArgs e)

{

string inValue;

double purchaseAmt, percent, ans;

inValue = txtPurchase.Text;

while (double.TryParse(txtPurchase.Text,out purchaseAmt)==false)

{

MessageBox.Show("Value entered must be numeric");

txtPurchase.Text = "0.0";

txtPurchase.Focus();

} Review TaxApp Example

Page 46: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 46

Adding Button Objects to

TaxApp Form (continued) btnCompute_Click( ) ( … continued)

inValue = label5.Text; //inValue previously declared as string

inValue = inValue.Remove(inValue.Length-1, 1);

percent = double.Parse(inValue) / 100;

ans = (purchaseAmt * percent) + purchaseAmt;

txtTotalDue.Text = String.Format("{0:C}", ans).ToString();

}

Parse( ) used

here as opposed

to TryParse( )

…since value is

being retrieve

from TextBox

Page 47: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 47

TaxApp Form

Figure 9-15 Tax calculator output

AcceptButton

property on the

form

was set to

btnCompute

Page 48: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 48

TempAgency

Application

Example

Figure 9-16 Problem specification for TempAgency

Page 49: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 49

TempAgency Application

Example (continued)

Table 9-9 Instance field members for the Employee class

Page 50: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

TempAgency Application

Example (continued)

C# Programming: From Problem Analysis to Program Design 50

Table 9-10 Constant field members for the Employee class

Page 51: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 51

Figure 9-17 Prototype for TempAgency example

TempAgency Application Example

(continued)

Page 52: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 52

TempAgency

Application

Example

(continued)

Figure 9-18 Class diagrams for TempAgency

example

Page 53: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 53

Algorithm for TempAgency

Figure 9-19 Pseudocode for the Employee class for the

TempAgency example

Page 54: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 54

Test Data for TempAgency

Table 9-11 Desk check test plan of TempAgency example

Page 55: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 55

Properties for TempAgency

Table 9-12 Properties set for the TempAgency example

Page 56: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 56

TempAgency Properties (continued)

Table 9-12 Properties set for the TempAgency example

Page 57: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 57

Properties for TempAgency

Table 9-12 Properties set for the TempAgency example

Page 58: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 58

Properties for TempAgency

Table 9-12 Properties set for the TempAgency example

Page 59: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 59

Properties for TempAgency

Table 9-12 Properties set for the TempAgency example

Page 60: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 60

Properties for TempAgency

Table 9-12 Properties set for the TempAgency example

Page 61: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 61

Properties for TempAgency

Table 9-12 Properties set for the TempAgency example

Page 62: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 62

Properties for TempAgency

Table 9-12 Properties set for the TempAgency example

Review TempAgency Example

Page 63: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 63

TempAgency Example

Figure 9-20 First user interface for the payroll application

Page 64: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 64

TempAgency Example (continued)

Figure 9-21 Output produced when the Calculate button is clicked

Page 65: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

Coding Standards • Guidelines for Naming Controls

– Consistency

– Use appropriate prefix for controls

C# Programming: From Problem Analysis to Program Design 65

Table 9-13 Example

prefix identifiers for

controls

Page 66: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

Resources

C#: Windows Controls –

http://csharpcomputing.com/Tutorials/Lesson9.htm

Visual C# Tutorials - Windows Forms –

http://visualcsharptutorials.com/windows-forms

Beginners Guide To User Interface Design in C# –

http://www.thetechlabs.com/interfaces/user-interface-design/

Free C# Tutorials –

http://www.homeandlearn.co.uk/csharp/csharp.html

C# Programming: From Problem Analysis to Program Design 66

Page 67: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 67

Chapter Summary

• Windows versus console applications

• Graphical user interfaces

• Elements of good design

• Visual Studio with Windows-based applications

– Drag-and-drop construction

Page 68: Introduction to Windows Programming - Electrical ...cis.csuohio.edu/~matos/notes/ist-211/csNotes/9781285096261_ch09... · Introduction to Windows Programming ... Form1 winForm = new

C# Programming: From Problem Analysis to Program Design 68

Chapter Summary (continued)

• Properties

– Getters

– Setters

• Controls as objects

– Buttons

– Labels

– TextBox