hello world in c++ and microsoft visual c++. directions to begin a project 1. go to all programs 2....

26
Hello World In C++ and Microsoft Visual C++

Upload: egbert-hancock

Post on 11-Jan-2016

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 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

Hello World

In C++ and Microsoft Visual C++

Page 2: 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

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

Page 3: 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

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.

Page 4: 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

• 3. Now to the same for the solutions explorer, which can also be found under the view menu in other windows.

Page 5: 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

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

Page 6: 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

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.

Page 7: 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

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

Page 8: 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

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.

Page 9: 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

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

Page 10: 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

Saving your work

• Click file menu• Click Save All• ALWAYS USE SAVE ALL! Never save as

Page 11: 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

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? _____________

Page 12: 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

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

Page 13: 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

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.

Page 14: 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

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

Page 15: 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

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

Page 16: 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

More control names and properties

• textBox1 ->BackColor , background color property

• For form1 use• this ->BackColor

Page 17: 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

Strings

• Use quotation marks, to deliminate strings

Page 18: 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

=

• Assignment operator• Makes something equal to something else

• textBox1-> Text = “Hello World!”;

Page 19: 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

Semicolons;

• Most C++ statements end in a semicolon• Your code will not execute properly without

the semicolon

Page 20: 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

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.

Page 21: 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

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.

Page 22: 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

Task 2: Add more Buttons

• Add three more buttons

Page 23: 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

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!

Page 24: 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

Task 4: Change the Text Properties of each Button

• Click for a green message• Click for a Red messageEtc.

Page 25: 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

Task 5: Change the textbox text color and background color

• textBox1 -> ForeColor = Color::Red;

• textBox1-> BackColor

Page 26: 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

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.