C#制作欢迎界面

来源:互联网 发布:淘宝直通车手机端投放 编辑:程序博客网 时间:2024/05/18 02:17

(1)设置窗体的属性

    StartPosition:CenterScreen

    FormBoderStyle:None

(2)添加背景图片

    在属性面板的BackgroundImage中添加背景图片

(3)为窗体添加Timer组件,以实现窗体的淡入淡出效果。

(4)编写代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WelcomeFormDemo
{
    public partial class SplashScreen : Form
    {
        public SplashScreen()
        {
            InitializeComponent();
        }

        private void SplashScreen_Load(object sender, EventArgs e)
        {
            // 设置欢迎界面的大小
            this.ClientSize = this.BackgroundImage.Size;
            this.Opacity = 0; // 透明界面
            this.timer1.Interval = 50; // 设置Timer的时间间隔
            this.timer1.Enabled = true;

            this.timer1.Start(); // 开始Timer
        }

        private void Timer_Tick(object sender, EventArgs e)
        {
            this.Opacity += 0.02;
            if (this.Opacity >= 1)
            {
                this.timer1.Stop();
                this.Close();
            }
        }
    }
}

原创粉丝点击