如何使图片出现在Microsoft Visual C#5秒后? [英] How to make a picture appear after 5 seconds in Microsoft Visual C#?

查看:255
本文介绍了如何使图片出现在Microsoft Visual C#5秒后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这个形象定时器设置为5秒后出现,但不知道该怎么做。到目前为止,我已经做了周围形成图像反弹,但我想要的图像,同时5秒后出现反弹。

 使用系统; 
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data这;
使用System.Drawing中;
使用System.Linq的;
使用System.Text;使用System.Windows.Forms的
;

命名空间弹跳
{
公共部分Form1类:表格
{

INT HORIZ,VERT,一步;

公共Form1中()
{
的InitializeComponent();
}

私人无效timer1_Tick_1(对象发件人,EventArgs五)
{
//图像是在计时器
$ B $每间隔移动b goblin.Left = goblin.Left +(HORIZ *步骤);
goblin.Top = goblin.Top +(垂直*步骤);


//如果妖精已经打到了边RHS,如果有改变方向离开
如果((goblin.Left + goblin.Width)> =(Form1.ActiveFor​​m。宽度 - 步))
HORIZ = -1;

//如果妖精已经打到了LHS边缘,如果有改变方向正确
如果(goblin.Left< =步)
HORIZ = 1;

//如果妖精已经打到了底部边缘,如果是这样改变方向向上
如果((goblin.Top + goblin.Height)> =(Form1.ActiveFor​​m.Height - 步) )
VERT = -1;

//如果妖精击中的顶部边缘,如果是这样改变方向向下
如果(goblin.Top<工序)
VERT = 1;
}


私人无效Form1_Load_1(对象发件人,EventArgs五)
{
//一声形式负载启动妖精开始移动
//设置intial方向
HORIZ = 1; //启动在朝好的方向发展
VERT = 1; //开始下降
步骤= 5;
timer1.Enabled = TRUE;

}

}
}


解决方案

这应该这样做。

 使用System.Timers; //这是Timer类的生活。 

定时fiveSecondTimer =新定时器(5000);
fiveSecondTimer.Elapsed + =()=> {} ShowImageHere; //这是手短$ B($ B fiveSecondTimer.Start);


I want this image timer to appear after 5 seconds but don't know how to do it. So far I have made the image bounce around the form but I want the image to appear while bouncing after 5 seconds.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Bounce
{
    public partial class Form1 : Form
    {

        int horiz, vert, step;

        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick_1(object sender, EventArgs e)
        {
            //image is moved at each interval of the timer

            goblin.Left = goblin.Left + (horiz * step);
            goblin.Top = goblin.Top + (vert * step);


            // if goblin has hit the RHS edge, if so change direction left
            if ((goblin.Left + goblin.Width) >= (Form1.ActiveForm.Width - step))
                horiz = -1;

            // if goblin has hit the LHS edge, if so change direction right
            if (goblin.Left <= step)
                horiz = 1;

            // if goblin has hit the bottom edge, if so change direction upwards
            if ((goblin.Top + goblin.Height) >= (Form1.ActiveForm.Height - step))
                vert = -1;

            // if goblin has hit the top edge, if so change direction downwards
            if (goblin.Top < step)
                vert = 1;
        }


        private void Form1_Load_1(object sender, EventArgs e)
        {
            //Soon as the forms loads activate the goblin to start moving 
            //set the intial direction
            horiz = 1;  //start going right
            vert = 1;   //start going down
            step = 5;
            timer1.Enabled = true;

        }

    }
}

解决方案

this should do it.

using System.Timers; // this is Where the timer class lives.

Timer fiveSecondTimer = new Timer(5000);
fiveSecondTimer.Elapsed += () => { ShowImageHere }; //This is short hand 
fiveSecondTimer.Start();

这篇关于如何使图片出现在Microsoft Visual C#5秒后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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