一段时间后隐藏图像 [英] Hide image after some time

查看:97
本文介绍了一段时间后隐藏图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,当我点击按钮时,我在Form中绘制一个图像,是否有一些方法,在点击按钮一段时间后例如5秒后图像会隐藏自己?谢谢你的回答。

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.

推荐答案

你可以用一个计时器来达到这个目的。



You could use a timer to achieve this.

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();
        }
    }
}





当您按下按钮时,包含图像的图片框

变得可见,计时器启动。

5000毫秒后,计时器过去,图片框变得不可见。



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.


你可以使用计时器 [ ^ ]将计时器设置为5秒的类,然后可以删除,删除或隐藏控件。



You can use the timer[^] class to set a timer for 5 seconds, and after that you can delete, remove, or hide the control.

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
}





确保在显示图像时启动计时器;所以5秒后它将被删除(隐藏)。



Make sure you start the timer when you show the image; so after 5 seconds it will be removed (hidden).


我希望下面的链接对你有用



链接1

链接2
I hope below link is useful for you

Link 1
Link 2


这篇关于一段时间后隐藏图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆