Sign in to follow this  
OPODGG

How to CODE programs. (For Begginers)

Recommended Posts

This is a basic Program to introduce you to the world of code.

 

Today I am going to help you learn how to program simple to complex (today we are sticking to simple) things in Visual Studios (which is what I use to code).

 

Things you will need:

C# 2017 community edition. (https://visualstudio.microsoft.com/vs/community/)

Like 1% of a brain considering everyone should be able to code if they try

 

Alright, First things first is open up visual studios. You cant really program if you don't even got the program tool on.

Go to "File" on the top left and press "New", after that press "Project" (you can press CTRL + SHIFT + N to do the same thing)

A new mini window should appear and all you have to do are 4 things.

1: Make sure "Windows Forms App (.NET Framework)" is selected. (you can either click it again or make sure it has a light gray highlight on it)

2: To the right of "Name:", Put whatever name you want to name the program, for this example we are going to name this "Hello World".

3: Press "Browse" and make sure that it is someone you can keep it for later, Flash Drive, Home Screen, wherever you want to access it from later.

4: Press "OK" on the Bottom-Right to start everything.

 

First thing you are going to notice, to the left of your screen there is a "Toolbox" which is where you get items such as labels and buttons to make the GUI (The Screen) look pretty.

Second thing you should notice, to the right there will be a "Properties" Tab, which is where you edit everything, (change the names, font size, etc.)

 

(If Something isn't there don't worry, I have mine set there by default but you can put them there with a few simple steps.

If you don't see the Toolbox Tab, There should be a mini little tab called Toolbox (on the left of your screen), click on that, then press the little pin emote thing to pin it so it wont hide itself when you click off it.

If you don't see the Properties Tab, There should be a mini little tab called Properties (on the right of your screen), click on that, then press the little pin emote thing to pin it so it wont hide itself when you click off it.

If you don't see either of those "Little pin emote thing" s, press the windows tab on the top middle area of your screen, then press 'Reset Windows Layout" and then repeat the steps above.)

 

First thing is first, on the Toolbox Tab we will need to drag out a button, self explanatory how to do it so I wont explain. After that go to the Toolbox and look for the "(Name)" icon and type in whatever you want, it cant have spaces so you can either leave it as is or type in camelCase (CamelCaseIsBasiclyTypingLikeThis) For the sake of this I wont touch it and will leave it as "Button1".

Once done with that we will repeat the previous step, but this time we will be looking for "Text". For the sake of this I will leave it as "Button1" but I wanted to show you guys these two things because they usually become very important if you are making a project with multiple for 1 thing, such as buttons and labels.

 

Now we get to the "Coding" part of this. Remember, this isn't a complex thing so what I will be doing is just showing you one line of code and explaining how everything works and how you can be creative when making programs.

 

Right now you should see a screen with this:

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace Hello_World

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)

        {

            

        }

    }

}

 

 

This stuff means a lot but we wont be covering it for the meantime.

 

I want you guys to type this thing into the space between Messagebox.show("Hello World")

        

        private void button1_Click(object sender, EventArgs e)

        {

               Messagebox.show("Hello World")

        }

 

 

As you will see, there should be a error appearing right now.

If you go over the red squiggly mark, it should say something along these lines. "; expected"

What it means here is that the code doesn't have a end so it is just waiting for the next command.

Put the SemiCollon after the line and make it look like this.

 

        private void button1_Click(object sender, EventArgs e)

        {

               Messagebox.show("Hello World");

        }

 

Now if you press "Start" in the top middle of your screen, you will see the first screen we were at, but this time you will see that the button is highlighted.

Click the button.

 

(exit out of the 2 new screens that poped out)

 

basicly all that you did was made a Messagebox, show itself and say "Hello World"

Coding is basicly just telling a idiot to do something in a very basic way.

 

Here is a example of a code I made. Other than the Const decimal number2=2m; and the Const decimal number1=1m; everything should be self explanatory when you just read it.

 

        private void PlayButton_Click(object sender, EventArgs e)

        {

            try

            {

                const decimal number2=2m;

                const decimal number1=1m;

                if (number1 == Convert.ToDecimal(SongNumberTextBox.Text))

                {

                    webBrowser1.Navigate("youtube.com");

                    CurrentSongTextBox.Text = ("Youtube's a song now.");

                }

                else

                {

                    if (number2 == Convert.ToDecimal(SongNumberTextBox.Text))

                    {

                        webBrowser1.Navigate("google.com");

                        CurrentSongTextBox.Text = ("Google's a song now.");

                    }

                }

            }

            catch (Exception)

            {

                MessageBox.Show("I'm sorry but what you inputed was not valid. Please try again!");

            }

 

 

All that this is, is just making a video pop up on a webbrowser (which you guys have on your toolbox btw, kinda cool) everything should be easy to read.

 

Anyways, I want you guys to start tinkering around and trying to make a little project with what common sense you guys actually have (the more the merrier).

 

That will be all for today, Have a nice day!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this