Presentation is loading. Please wait.

Presentation is loading. Please wait.

VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 1B Introduction (Tutorial)

Similar presentations


Presentation on theme: "VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 1B Introduction (Tutorial)"— Presentation transcript:

1 VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 1B Introduction (Tutorial)

2 Tutorial: Hello World! Visual C++ Programming 2  Problem Analysis  When the user clicks the button “Hello World!” appears in the textbox.  Design  This program has an interface containing One button One textbox

3 Interface Design Sketch Visual C++ Programming 3

4 Development and Preliminary Testing Visual C++ Programming 4  Create a new Visual C++ project called “Hello World”  Set up the IDE so that these tabbed windows are available  Solution Explorer  Toolbox  Properties window

5 Creating a New Project Visual C++ Programming 5

6 Naming and Saving the Project Visual C++ Programming 6

7 Setting up the IDE Visual C++ Programming 7

8 Development and Preliminary Testing (continued) Visual C++ Programming 8  Use the Toolbox to locate controls and place them on the form  Use the Properties window to change the attributes of an object  Run the program by clicking the “Start Debugging” button

9 Opening the Toolbox Visual C++ Programming 9

10 Select the Properties Window Visual C++ Programming 10

11 Toolbox and Properties Window Visual C++ Programming 11

12 Repositioning the Properties Window Visual C++ Programming 12

13 Positioning the Solution Explorer Visual C++ Programming 13

14 Creating textBox1 Visual C++ Programming 14

15 Creating button1 Visual C++ Programming 15

16 Using the Properties Window Visual C++ Programming 16

17 Changing the Text Property of button1 Visual C++ Programming 17

18 Changing the Text Property of Form1 Visual C++ Programming 18

19 Running Your Program Visual C++ Programming 19

20 Getting Rid of an Unnecessary Dialog Box Visual C++ Programming 20

21 Your Running Program Visual C++ Programming 21

22 Development and Preliminary Testing (continued) Visual C++ Programming 22  To create a click event handler double click on a button.  The Code Editor window opens and the cursor is positioned within the event handler  When you have finished entering your C++ code run the program and test it

23 The Code Window Visual C++ Programming 23

24 The button1_Click() Event Handler Visual C++ Programming 24

25 Example 1-1 Visual C++ Programming 25

26 The Statement Completion Dropdown Box Visual C++ Programming 26

27 Completed button1_Click() Event Handler Code Visual C++ Programming 27

28 Understanding the Code Visual C++ Programming 28  Windows Forms Designer code  Created automatically  Defines the Form1 class definition  Do not modify it or your program may not work  Keywords  Keywords have a special meaning in Visual C++ and can only be used in their designated context  Keywords are automatically colored blue  Example: this->BackColor  See Appendix B for a list of C++ keywords

29 Understanding the Code (Continued) Visual C++ Programming 29  Control names and properties  Attributes and methods belonging to a control object are referred to using the operator (->)  Example: textBox1->Text  Strings and delimiters  A string of characters is designated using a pair of quotation marks (double quotes) as delimiters  Example: “Hello World!”  Strings are automatically colored maroon

30 Example 1-2 Visual C++ Programming 30

31 Example 1-3 Visual C++ Programming 31

32 Understanding the Code (Continued) Visual C++ Programming 32  The assignment operator (=)  The value on the right side of the = operator is assigned to the location on the left  Example: textBox1->Text = “Hello World!”;  In this example, the string “Hello World!” is assigned to the Text property of textBox1  Semicolons  Almost every C++ statement is followed by a semicolon (;)  Forgetting to put in a semicolon will prevent your program from compiling

33 Assignment Statement Visual C++ Programming 33

34 Testing the Completed Program Visual C++ Programming 34  Your program should  Have one button and one textbox on the form  Display “Hello World!” in the textbox when the button is clicked

35 Hello World Program Visual C++ Programming 35

36 Debugging a Program Visual C++ Programming 36  Remove the semicolon (;) from the end of the line you entered earlier  Now run your program and look at the error messages displaying in the Output window  Find the error number and description  Find the line at which the error was detected by the compiler  Fix the error and run your program again

37 Program Error Dialog Box Visual C++ Programming 37

38 Locating an Error Visual C++ Programming 38

39 Locating an Error Line Visual C++ Programming 39

40 On Your Own Visual C++ Programming 40  Change the textbox font  Add more buttons  Create click event handlers for the new buttons  Change the Text properties of each button  Change the textbox foreground and background colors  Change the background color of the form

41 Font Property in Properties Window Visual C++ Programming 41

42 Font Dialog Box Visual C++ Programming 42

43 Colored Text in textBox1 Visual C++ Programming 43

44 Color Values Visual C++ Programming 44

45 Completed Project Visual C++ Programming 45


Download ppt "VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 1B Introduction (Tutorial)"

Similar presentations


Ads by Google