Sign in to follow this  
OPODGG

How to CODE programs. (For Begginers) Part 2

Recommended Posts

Look I already am mad because I finished the post and when I was just about to submit it I accidentally closed it so I'm am just going to skip to the point...

 

LEAVE ME A LIKE PLEASE I NEED IT TO FEED MY CHILDREN T>T

(Plus if you leave me a like ill dm you and give you a free lesson on how to code something else)

(During this project I also used the hide ability and I don't know if that's making you comment or if that's making you click to see what is there, 1 way to find out though)

 

What you will need:

1.) Visual Studios (Which you should have downloaded from my previous tutorial)

2.) Download two images for reasons you'll understand in a minute. (I suggest a front and a back) http://tinyurl.com/yy5lgbm5

3.) 1.1% of a brain and that's pretty much it.

 

First things first, open up Visual Studios and make a new project (For the sake of this, I'm going to name it Card Flipper)

 

This project is going to be introducing you to two new items. A "PictureBox" and a "Timer" (timer wasn't really needed but I decided to do it because I should do more things with less time ;D)

 

First off, we are going to need to drag out 2 PictureBoxes from "Toolbox" (if you cant find it scroll down and you'll see it eventually.)

 

Your tab should be two dotted boxes, but what we will do now is give them a photo (with the two photos we downloaded from earlier)

You're going to notice that they are not the full images, so what you will do is click a picture box and drag the bottom right side until you can see the full photo on both. (I have ocd so I made them identical in size)

 

Now, you will need to drag something else out, and that is the timer, so go to the toolbox and drag it out. (You will just need one)

 

Lets get on with the editing. Go to the pictureboxes again and change the name so you can tell which side is which, I named them CardFront and CardBack because that's just obvious to me. you can also edit the timer but I find no reason in doing so because there is only one timer.

 

What we will need to do is turn the card's front invisible (we can still see it but when you run the program you wont be able to)

What you will need to do is go to the properties tab and start scrolling until you find "visible". to the right of "visible" there will be another tab called "true" double click "true" and it becomes "false". run your program so you can see what you just did (if you did it right). when the program loads you'll notice that there is only 1 side of the card there because the other one is invisible mate.

 

exit out of that little demonstration (the window that came up after you pressed start)

 

Now we will start coding. Double tap the card back, so that you can go code into it.

your code right now should look like this (the names might be different thought)

 

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 Card_Flipper

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void CardBack_Click(object sender, EventArgs e)

        {

 

        }

    }

}

 

What you will do now is plug in this line. " CardFront.Visible = true; "

Your code should look like 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 Card_Flipper

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void CardBack_Click(object sender, EventArgs e)

        {

            CardFront.Visible = true;

        }

    }

}

 

Since we "Flipped" the card,we want to make the back go invisible. Try to code it yourself.

[hide] Your Code should look like this: (the card back name).visible=false;[/hide]

(BTW add this code between the two brackets, we will use it for later. Timer1.enabled=true;)

Congratulations if you were able to code that yourself :D

Press "Start" so you can see your amazing coding in action.

 

But now you will notice that if you click the other card, it wont flip it again. nor will it do it by waiting!

(If you honestly want to make the other card flip when you click it just do all the code we did but backwards.)

Now we are going to fix that with that amazing timer that we added earlier.

Exit out of the window that was just made, and press "Form1.cs [Design]*" on the top middle of your screen.

 

You will see a little war below the GUI (the window where you drag and drop stuff) and it will say "timer1" (if you didn't change it)

I need you to double click that so that we go into the code of the timer and program it too!

 

Right now your code should look like 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 Card_Flipper

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void CardBack_Click(object sender, EventArgs e)

        {

            CardFront.Visible = true;

            CardBack.Visible = false;

            timer1.Enabled = true;

        }

        private void timer1_Tick(object sender, EventArgs e)

        {

           

        }

    }

}

 

What I need you to do is to start writing in between the brackets below "private void timer1_Tick(object sender, EventArgs e)"

I want you to code this part on your own, but if you cant just check out the answer.

[hide]The correct answer was:

        private void timer1_Tick(object sender, EventArgs e)

        {

            CardFront.Visible = False;

            CardBack.Visible = True;

            timer1.Enabled = False;

 

        }

[/hide]

 

What you did with the timer was just revert everything back to how it originally started! its honestly simple if you think about it. Anyways, press "Start" and check it out.

There is just one more thing that I want to cover before I leave it here for today. If you pressed start and saw what you did, you would have noticed that when you clicked it, it appeared and disappeared in a flash. If you want to speed it up or slow it down go to the properties of the timer (click it once) and you will see "Interval" 1000 is equivalent to 1 second, so when it was at 100, it was counting at .1 second. so if you want to speed it up, put 50 (which means .05 of a second) and if you want to slow it down just add more time, I feel like 2000+ should be enough to see the card thought. Anyways, that's all for today. Remember, leave a like because I need to feed my kids, they love likes :D

Share this post


Link to post
Share on other sites

This is a bump

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