CSCI 3328 Object Oriented Programming in C Chapter

  • Slides: 23
Download presentation
CSCI 3328 Object Oriented Programming in C# Chapter 2: Introduction to Visual C# Programming

CSCI 3328 Object Oriented Programming in C# Chapter 2: Introduction to Visual C# Programming Xiang Lian The University of Texas – Pan American Edinburg, TX 78539 [email protected] edu

Objectives • In this chapter, you will – Become familiar with the IDE, Visual

Objectives • In this chapter, you will – Become familiar with the IDE, Visual Studio – Learn more controls of Visual C# programming – Discover differences between different controls – See more examples of designing the graphical interface – Become aware of the console application, in addition to windows forms application 2

Demo in the Class form Text Back. Color label button 3

Demo in the Class form Text Back. Color label button 3

Integrated Development Environment (IDE) 4

Integrated Development Environment (IDE) 4

Integrated Development Environment (cont'd) • Menu bar – File: Open/New/Save/Close projects or files –

Integrated Development Environment (cont'd) • Menu bar – File: Open/New/Save/Close projects or files – Edit: Undo/Redo, Copy, Paste, Cut – View: Other Windows Properties – Build – Debug: Start Debugging, Step Into, Step Over 5

Integrated Development Environment (cont'd) • Buttons – For files and edit – For compilation

Integrated Development Environment (cont'd) • Buttons – For files and edit – For compilation – For debugging • If some buttons do not appear, right click your mouse on the tool bar and customize buttons 6

Integrated Development Environment (cont'd) • Windows show all files events Properties Solution Explorer 7

Integrated Development Environment (cont'd) • Windows show all files events Properties Solution Explorer 7

Visual C# Controls • Choose Windows forms application • What you see is the

Visual C# Controls • Choose Windows forms application • What you see is the IDE (Integrated Development Environment) • Use Sizing handle to make the form • Adjust the size of the properties window • In the toolbox – Use common controls • Start placing objects on the form • Place a button, label it OK and add code this. Close() 8

Controls 9

Controls 9

Text. Box • Difference between label and text boxes • Properties window – Changing

Text. Box • Difference between label and text boxes • Properties window – Changing name and text – Border Style – Back. Color – Font Size – Visible – Tab. Index 10

Picture. Box • Properties – Image Local resource Import – Size. Mode: Normal, Stretch

Picture. Box • Properties – Image Local resource Import – Size. Mode: Normal, Stretch Image, Auto. Size, Center. Image, Zoom 11

Group. Box • Properties – Text • Radio. Button – Checked = "false" –

Group. Box • Properties – Text • Radio. Button – Checked = "false" – Add radio buttons to the group box – At most one radio button is checked at a time • Check. Box – 0 or any number of boxes are checked 12

Other Interesting Controls • Progress. Bar – Value: 50 • List. Box – Items:

Other Interesting Controls • Progress. Bar – Value: 50 • List. Box – Items: enter strings one per line • Combo. Box 13

Adding a Pop-Up Message Box Add a form to the application Add this line

Adding a Pop-Up Message Box Add a form to the application Add this line Message. Box. Show("Hello!"); Message. Box. Show("Hello!", "Show Message"); 14

Example of GUI Design • Notepad GUI – Menu strip – Rich Text. Box

Example of GUI Design • Notepad GUI – Menu strip – Rich Text. Box 15

Example of GUI Design (cont'd) • Calendar GUI – Label – Month. Calendar –

Example of GUI Design (cont'd) • Calendar GUI – Label – Month. Calendar – Rich. Text. Box 16

Analyzing a Program • • Line numbers: not part of Visual C# Comments: (Lines

Analyzing a Program • • Line numbers: not part of Visual C# Comments: (Lines 23 -29) Classes: class declaration (Lines 12 -31) Keywords: Case sensitive (the same as C++) • public, private, class • partial event handling 17

Variable Declaration and Naming • Variable declaration – Same as C++ • Data types:

Variable Declaration and Naming • Variable declaration – Same as C++ • Data types: int, float, double, char, etc. • Variable name: (1) digits, letters, underscore ("_"), and (2) cannot start with a digit • int x = 1; • int x = 0, y = 1; • Naming convention – Camel case: e. g. first. Number 18

Assignment • Use DOT (. ) to refer to attributes of an object –

Assignment • Use DOT (. ) to refer to attributes of an object – E. g. , Label 1. Text • Use assignment operator (=) to give a value to a variable – E. g. , Label 1. Text = "haha" 19

Applications • In addition to Windows Forms Application, … • Console – Output appears

Applications • In addition to Windows Forms Application, … • Console – Output appears in console window – From Visual Studio choose C# and choose a new project, and choose Console Application – Give it a name 20

Demo of Hello Program string name; name=Console. Read. Line(); Console. Write. Line("Hello! " +

Demo of Hello Program string name; name=Console. Read. Line(); Console. Write. Line("Hello! " + name); Console. Write. Line("Welcome to Dr. Lian's C# Class!"); Console. Read. Line(); 21

Demo of Hello Program (cont'd) 22

Demo of Hello Program (cont'd) 22

Summary • IDE – Menu bar, buttons, windows, toolboxes • Controls – Text. Box,

Summary • IDE – Menu bar, buttons, windows, toolboxes • Controls – Text. Box, Picture. Box, Group. Box, etc. • GUI design – Examples • Program analysis • Windows Forms Application vs. Console Application 23