private void Welcome_Load(object sender, EventArgs e)
{
for (double d = 0.01; d < 2; d += 0.03)
{
System.Threading.Thread.Sleep(1);
Application.DoEvents();
this.Opacity = d;
this.Refresh();
}
for (double d = 1; d > 0; d -= 0.015)
{
System.Threading.Thread.Sleep(1);
Application.DoEvents();
this.Opacity = d;
this.Refresh();
}
}
淡入和淡出的代码,运行起来的时候,那个窗体没有连贯的淡入淡出,但是伴随着闪动.有什么办法让他不要闪吗?
是 重新刷新的 意思! 所以会闪烁的
for (double d = 0.01; d < 2; d += 0.03)
{
System.Threading.Thread.Sleep(1);
Application.DoEvents();
this.Opacity = d;
}
{
InitializeComponent();
this.Opacity = 0;
}
private void Form2_Load(object sender, EventArgs e)
{
this.Show();
for (double d = 0.01; d < 2; d += 0.03)
{
System.Threading.Thread.Sleep(1);
Application.DoEvents();
this.Opacity = d;
}
}
这次肯定可以了
2.这种事情不要兴师动众地用Thread还Sleep呢.用一个简单的Timer控件足矣.(个人看法)
{
Opacity += 0.1;
if (Opacity >= 1) timer1.Stop();
}
void Deeper()
{
timer1.Start();
}