Visual+Studio+Programming

= VISUAL STUDIO =

Basic Commands
Microsoft Visual Studio is an integrated development environment (IDE) from Microsoft. It can be used to develop interfaces, gadgets, applications, websites and web services in both native and management code for all platforms supported by Windows.

There are three main areas or windows that should be known when using visual studio. The ‘dockable’ windows show the toolbox, which adapts according to the project that you are creating. We also have the main windows, where you design the program, in Forms and design windows. Lastly we have a window to our right; this Project window shows the properties of an item in your form. The basic tools that we will initially learn are to add items to our form and then manipulate some of its properties.

media type="youtube" key="9PbNl0QEZfI?fs=1" height="385" width="480" align="center"

Once you have a Form [From1.] You can rename it or modify properties in the window to our right. In properties, you may name the form, or change attributes like color.

Moreover, you may add elements to the form. Using the toolbox (left) you can add buttons, images boxes, etc. You just have to drag them to the form and place them there. You can change the properties and activate properties and movement as outlined in the videos and below.

  media type="youtube" key="K2vqJxvg6JM?fs=1" height="385" width="480" align="center"

= How to create a program in which you can move an image around and count clicks? =



1. Create a new project in visual studio

**Moving an image! ** 2. From your "cuadro de herramientas or toolbox" select and drag 4 buttons to your form.

3. Click on your button and start editing the name of each of them to have: up, down, left and right (from the "properties" window select text and change it)

4. Add a picture box to your form and select an image

5. Double click the "right" button to open the Form1cs* tab and insert the following code:  pictureBox1.Location = new Point(pictureBox1.Location.X + 10, pictureBox1.Location.Y); This should make the image move to the right each time the button is clicked.

6. Double click the "left" to open the Form1cs* tab and insert the following code:  pictureBox1.Location = new Point(pictureBox1.Location.X - 10, pictureBox1.Location.Y); This should make the image move left ( notice that the there is only a change in x - 10)

7. Double click the "up" button to open the Form1cs* tab and insert the following code:  pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y - 10);

8. Double click the "down" button to open the Form1cs* tab and insert the following code: <span style="font-family: Arial,sans-serif; line-height: 21px; margin-bottom: 0pt;">pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y + 10);

<span style="font-family: Arial,sans-serif; line-height: 21px; margin-bottom: 0pt;">9. Now click on play (or press f5) to test the program, the image should move according to the button pressed independently of its current location

**<span style="font-family: Arial,sans-serif; line-height: 21px;">Adding a click counter! ** <span style="font-family: Arial,sans-serif; line-height: 21px; margin-bottom: 0pt;">1. Once the image is capable of moving around we will now add a click counter, to do so first from the "cuadro de herramientas" select and drag a label. <span style="font-family: Arial,sans-serif; line-height: 21px; margin-bottom: 0pt;">2. Double click any part of you program to open the Form1cs*, go to the top of the coding and look for the following:

public partial class Form1 : Form { public Form1 { InitializeComponent; }

3. Add the following codes so that it looks like this: public partial class Form1 : Form { <span style="font-family: 'Courier New'; font-size: 10pt; line-height: normal; margin-bottom: 0cm; text-indent: 35.4pt;">int contador; public Form1 { InitializeComponent; Contador = 0; }

4. Now double click a button and to every button, under the code it already has has add the following:

Contador = comtador + 1; Label1.Text ="clicks"+ contador;

5. Now your overall program should look like this:

public partial class Form1 : Form {  int contador; public Form1 { InitializeComponent; contador = 0; }

private void button2_Click( object sender, EventArgs e) { pictureBox1.Location = new Point (pictureBox1.Location.X,pictureBox1.Location.Y-10); contador = contador + 1; label1.Text = "clics" + contador; }

private void pictureBox1_Click( object sender, EventArgs e) {

}

private void button4_Click( object sender, EventArgs e) { pictureBox1.Location = new Point (pictureBox1.Location.X, pictureBox1.Location.Y +10); contador = contador + 1; label1.Text = "clics" + contador;

6. You can now check your program, it shoud allow you to move the image around while pressing the buttons and each time you press them, the label you added should count every click you do on the program. (In case it does not work, it is adviced to manually type the codes, also make sure to add capital letters to the required elements [label 1 - Label1])