通过timer控件和窗体的opacity属性,轻松实现窗体的淡入淡出(C#)

云想慕尘 2008-09-28 01:51:39

#region 窗体加载
private void Form1_Load(object sender, EventArgs e)
{
//timer控件ShowForm1
this.ShowForm1.Enabled = true; //控件是否激活
this.ShowForm1.Interval = 100; //Elapsed 事件的频率
//timer控件HideForm1
this.HideForm1.Enabled = false;
this.HideForm1.Interval = 100;
this.Opacity = 0.5; //设置窗体透明度
ShowForm1.Start(); //timer控件 ShowForm1开始
}
#endregion

#region 打开form1
private void ShowForm1_Tick(object sender, EventArgs e)
{
if (this.Opacity == 1) //如果窗体透明度达到 1
{
this.ShowForm1.Stop();
}
else //透明度小于 1
{
this.Opacity = this.Opacity + 0.1; //透明度递增

}
}
#endregion
#region 隐藏from1
private void HideForm1_Tick_1(object sender, EventArgs e)
{
this.Opacity = this.Opacity - 0.1; //透明度不等于 0
if (this.Opacity == 0) //透明度等于 0
{
this.HideForm1.Stop();
this.Hide();

}
}
#endregion
#region 关闭
private void button1_Click(object sender, EventArgs e)
{
this.HideForm1.Start();
}
#endregion
...全文
127 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧