Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hallo, I draw an image in Form when I click button, is there some method, that after some time after click on button for example 5 seconds the image will hide himself? Thank you for answer.
Posted
Comments
Tejas Vaishnav 5-Mar-15 6:29am    
you can search for timer, i think it will help you to achieve your goal
TheRealSteveJudge 5-Mar-15 8:50am    
Please have a look at the suggested solutions.
Are they helpful?
Thank you.

You could use a timer to achieve this.

C#
using System;
using System.Windows.Forms;

namespace WindowsFormsApplicationImageHide
{
    public partial class Form1 : Form
    {
        System.Timers.Timer timer;

        public Form1()
        {
            timer = new System.Timers.Timer(5000);
            timer.Elapsed += timer_Elapsed;

            InitializeComponent();
        }

        void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            pictureBox1.Visible = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            pictureBox1.Visible = true;

            timer.Start();
        }
    }
}


When you press the button the picture box containing an image
becomes visible and the timer is started.
After 5000 ms the timer elapses and the picture box becomes invisible.
 
Share this answer
 
You can use the timer[^] class to set a timer for 5 seconds, and after that you can delete, remove, or hide the control.

C#
Timer timer = new Timer(5000); // 5000ms = 5s
timer.Elapsed += Timer_Elapsed;
timer.Enabled = true;

// create the functions
static void Timer_Elapse(object sender, ElapsedEventArgs e)
{
    // Handle the event and hide the image
}


Make sure you start the timer when you show the image; so after 5 seconds it will be removed (hidden).
 
Share this answer
 
I hope below link is useful for you

Link 1
Link 2
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 5-Mar-15 6:56am    
Why are you giving a solution based in jQuery? The question is tagged with C#.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900