hello world in c++ and microsoft visual c++. directions to begin a project 1. go to all programs 2....
TRANSCRIPT
Hello World
In C++ and Microsoft Visual C++
Directions to begin a project
• 1. Go to All Programs• 2. Open Visual Studio C++• 3. Click on New Project• 4. Click CLR• 5. Click Windows Form Application• 6. Type in file name: Hello World!• 7. Location: desktop• 8. Click OK
Directions to set up IDE
We are going to dock three windows on the right side of the screen.1.Under the view menu, click on toolbox, drag to the right side of the screen, and click the stick pin to lock it on your screen.2. Under the view menu, click on other windows, click on properties window. Drag to right window.
• 3. Now to the same for the solutions explorer, which can also be found under the view menu in other windows.
Solution Explorer
• Displays the structure of your program• Shows that it is made of a number of files and
folders• These must be kept together.• Formal1.h file will contain your code• Other files support the way the program
works
Use the Toolbox to add a control: a textbox
• In toolbox, scroll down until you get to TextBox, double click. This will create a textbox in the upper left corner of form1, called textbox1
• Small white squares around the box indicate that it is highlighted or the selected object. Move the textbox to the middle of form1.
Use the Toolbox to add a control: a Button
• In toolbox, scroll down until you get to Button, double click. This will create a button, called button1, which is likely located over your textbox.
• Move the button below your textbox.
• Remember: the currently highlighted or active object’s information is in the property window
Using the properties window
• The attributes of a control are known as its properties.
1. Make sure the button1 is highlighted (active), then go to the properties window. You will see the properties for that button.
2. Scroll to Text, delete button1 and type in “Click for a Message”. Then press the enter key.
3. You should see Click for a Message on the button in the form now.
Can also change the properties of the form itself
• Click on the form anywhere except in the textbox or button.
• In the property window, scroll to Text, change it to Hello World! Press enter key.
• It’s usually a good idea to change the name of Form1 to the name of the program
Saving your work
• Click file menu• Click Save All• ALWAYS USE SAVE ALL! Never save as
How to Run the Program
• Click the Start Debugging Button (green triangle) on the toolbar.
• If you see a dialog box, click the box labeled Do not show this dialog again. Then click yes.
• Click the box on the program that says Click for message. What happens? _____________
Coding an Event Handler
• Double click the button on the form. • This opens the Code Editor Window, also
called the Code Window• This is the code that underlies the form.• The code is labeled Form1.h while the design
window is called Form1.h [Design]• DO NOT CHANGE THE CODE
Coding Event Continued
• The cursor is located at the end of the code prior to the closing of the curly bracket.
• Hit the enter key to go to a new line• textBox1->Text = “Hello World!”;
Save you program using SAVE ALLRun the program, using the green button.
Keywords
• Colored blue• Predefined meanings in C++, can’t be used for
anything else• Examples: this, false, private• This: used whenever a form wants to refer to
itself• Text or strings are colored blue
Control Names and Properties
• Form1, textbox1, button1• All controls have properties• textBox1 -> Text , is used to identify the text
property for textBox1• -> is the pointer membership operator. It
indicates (points to) a property belonging to an object. Can be used for any properties
More control names and properties
• textBox1 ->BackColor , background color property
• For form1 use• this ->BackColor
Strings
• Use quotation marks, to deliminate strings
=
• Assignment operator• Makes something equal to something else
• textBox1-> Text = “Hello World!”;
Semicolons;
• Most C++ statements end in a semicolon• Your code will not execute properly without
the semicolon
You will now complete 6 Tasks
• When you complete a task, you must call me over to see the finished program to get credit.
• Once I have checked it off, you can move to the next task.
Task 1: Change the Textbox Font
• The Font property controls the size and appears of the message.
• To change the Font you will need to click on the Elllipsis(…) to get the font dialog box.
• You may need to resize the box.
Task 2: Add more Buttons
• Add three more buttons
Task 3: Create click Event Handlers for Each buttton
• Have the buttons display the following messages, one for each button:
Hello Green World!Hello Red World!Hello Yellow World!Hello Blue World!
Task 4: Change the Text Properties of each Button
• Click for a green message• Click for a Red messageEtc.
Task 5: Change the textbox text color and background color
• textBox1 -> ForeColor = Color::Red;
• textBox1-> BackColor
Task 6: Change the Background Color of the Form
• Change the BackColor property of the form• Use the keyword this
• All tasks must be completed by the end of class on Thursday.