用VS创建一个名为Welcome的窗体
//去掉窗体的边框
FormBorderStyle设为:None;
//第一次启动窗体的位置
StartPosition=CenterScreen;
//窗体背景图
设置属性BackgroundImage
//在窗体中添加一个Timer组件:timer1
1. 指示淡入淡出变化方向的变量
public partial class Welcome : Form
{
//设置用于指示淡入淡出变化方向的变量
private bool bIsFade = true;
public Welcome()
{
InitializeComponent();
}.............
2添加timer1的Tick事件
private void timer1_Tick(object sender, EventArgs e)
{
if (bIsFade)
{
//由不透明变为透明
this.Opacity += 0.02;
//当完全不透明时再由不透明变为透明
if (this.Opacity >= 1)
{
bIsFade = false;
}
}
else
{
//由透明变为不透明
this.Opacity -= 0.02;
//当完全透明时停止计时器,并退出欢迎界面
if (this.Opacity <= 0)
{
this.timer1.Stop();
this.Close();
}
}
}
3添加Welcome窗口的load事件
//启动窗LOAD事件
private void Welcome_Load(object sender, EventArgs e)
{
//使欢迎界面的大小与背景图片的大小一样
this.ClientSize = this.BackgroundImage.Size;
//使欢迎界面全透明
this.Opacity = 0;
//设置timer1的时间间隔
this.timer1.Interval = 50;
//使记时器timer开始工作
this.timer1.Enabled = true;
this.timer1.Start();
}
OK了
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23109131/viewspace-630567/
,如需转载,请注明出处,否则将追究法律责任。