VC#中渐显窗口的方法

VC#中渐显窗口的方法
有时在编程中需要渐渐显示窗口或者对话框,这种技术在VC#中非常简单,下面给出了这种技术的方法:

首先,添加一个Timer控件,该控件按默认的属性设置,然后给Timer控件添加一个事件Tick,然后在该事件中添加如下代码:

private void timer1_Tick(object sender, System.EventArgs e)
  {
   if(this.Opacity<1)
   {
     this.Opacity=this.Opacity+0.05;//随时间增加Opacity的值,每次增加0.05
   }
   else
   {
     this.timer1.Enabled=false;
   }
  }

然后在Form的Load事件中添加如下代码即可

private void Form1_Load(object sender, System.EventArgs e)
  {
      this.timer1.Enabled=true;//使时间控件生效
   this.Opacity=0;//设置初始透明度 Opacity:0-1.0, 0为全透明,1.0为不透明
  }

超级容易。

猜你喜欢

转载自blog.csdn.net/hyrzzh/article/details/21993817