WPF启动屏幕SplashScreen

SplashScreen类为WPF应用程序提供启动屏幕。

方法一:设置图片属性

1. 添加启动图片到项目中

2. 设置图片属性的Build Action为SplashScreen

方法二:编写代码

1. 在App.xaml.cs中重写OnStartUp方法:

using System;
using System.Windows;

namespace StaticLanguageSelect
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            //根据图片路径,实例化启动图片
            SplashScreen splashScreen = new SplashScreen("\\3-2.png");
            splashScreen.Show(false);

            //上面Show()方法中设置为true时,程序启动完成后启动图片就会自动关闭,
            //设置为false时,启动图片不会自动关闭,需要使用下面一句设置显示时间,例如5s
            splashScreen.Close(new TimeSpan(0,0,5));

            base.OnStartup(e);
        }
    }
}

  

猜你喜欢

转载自www.cnblogs.com/mr-hu2009/p/12919024.html