Date post: | 29-Dec-2015 |
Category: |
Documents |
Upload: | wilfrid-lloyd |
View: | 229 times |
Download: | 2 times |
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
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
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
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
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
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
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
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
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
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