Hugo Löwgren
Hugo Löwgren

Reputation: 47

Change visibility of a picture when button is pressed

I have been working on a school project for months now and I'm almost done. However there's a slight bump at the moment.

You see, I want a picture to show up for about a second, or so, when I've pressed a certain key using a timer.

This is my code so far:

if (e.KeyData == Keys.Down && up == false)
{
    down = true;
    up = false;
    right = false;
    left = false;
    timerArrows.Enabled = true;

    if (timerArrows.Enabled == true)
    {
        pictureBox1.Visible = true;
    }
    else
    {
        pictureBox1.Visible = false;
    }                
}

This doesn't work and I have no idea how you should write the code differently.

Upvotes: 0

Views: 263

Answers (1)

Darren
Darren

Reputation: 70776

Since it's school work I won't write the program for you.

I think what you should be doing is:

When the down key is pressed you want to enable the timer (With an interval of 1000 milliseconds) and show the pictureBox1. After the timer has elapsed you want to disable the timer and hide the picture box.

Without seeing the full source code

        right = false;
        left = false;

Maybe unnecessary.

As a side note look at breakpoints and debugging in Visual Studio, you can see what is going on at runtime and it will help you solve future problems.

Upvotes: 2

Related Questions