本文介绍了计时器的WinForms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用一个定时器来创建一个启动画面。
我想要做的是使窗体淡入和淡出。我开始与制作形式不透明度0在窗体的构造,并通过在窗体加载方法触发定时器。
现在在我的 Timer_Tick 方法,我一直在,比方说,0.2增加了透明度。
我想我会开始降低不透明度一旦定时打一半的时间,但我无法做到这一点。

I'm using a timer to create a Splash Screen.What I want to do is to make the form fade-in and fade-out. I started with making the form opacity 0 in the form's constructor, and by triggering the timer in the Form load method.Now in my Timer_Tick method, I keep increasing the opacity by, say, 0.2.I figured that I'd start decreasing the opacity once the timer hits half its interval, but I'm unable to do that.

我不是很清楚与定时器是如何工作的,因为它是,但我想实现这样的:

I'm not very clear with how the timer works as it is, but I wanted to implement something like this:

if(Whatever_Timer_Value_Is <= Interval/2)  //Can't achieve this :s
this.Opacity += 2;
else
this.Opacity -=2 ;



So..is有办法在任何时刻,以得到定时器的值?或有任何其他方式做到这一点?
请保持简单。我只是一个业余爱好者。 X(

So..is there a way to get the value of the Timer at any instant? Or is there any other way to do this?Please keep it simple. I'm just an amateur. X(

推荐答案

尝试创建飞溅第二种形式:

Try creating a second form for splash:

Form splash = new Form();

public Form1()
{
    InitializeComponent();
    this.Visible = false;
    splash.Opacity = 0;
    splash.Show();
    _timerShow();
    _timerHide();
    this.Visible = true;
}

private async void _timerShow()
{
    while(splash.opacity!=1)
    {
        await Task.Delay(50);
        splash.opacity +=.01;
    }
}

private async void _timerHide()
{
    while(splash.opacity!=0)
    {
        await Task.Delay(50);
        splash.opacity -=.01;
    }
}

这篇关于计时器的WinForms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 06:30
查看更多