WinForm下Splash(启动画面)制作



 
      
     本代码可以依据主程序加载进度来显示Splash。
    static class Program
    {
        /// <summary>
        /// 主程序的入口点在此设置,包括一些初始化操作,启动窗体等
        /// </summary>
        private static ApplicationContext context;
        [STAThread]     
        static void Main()
        {
            Application.EnableVisualStyles();                       //样式设置
            Application.SetCompatibleTextRenderingDefault(false);   //样式设置
            Splash sp = new Splash();                               //启动窗体
            sp.Show();                                              //显示启动窗体
            context = new ApplicationContext();
            context.Tag = sp;
            Application.Idle += new EventHandler(Application_Idle); //注册程序运行空闲去执行主程序窗体相应初始化代码
            Application.Run(context);
        }
        //初始化等待处理函数
        private static void Application_Idle(object sender, EventArgs e)
        {
            Application.Idle -= new EventHandler(Application_Idle);
            if (context.MainForm == null)
            {
                Main mw = new Main();
                context.MainForm =mw;
                mw.init();                                  //主窗体要做的初始化事情在这里,该方法在主窗体里应该申明为public
                Splash sp = (Splash)context.Tag;
                sp.Close();                                 //关闭启动窗体
                mw.Show();                                  //启动主程序窗体
            }
        }
    }
        Splash窗体的相关属性设置:
        BackgroundImage:载入你想作为启动画面的图片;
        ControlBox:False;
        FormBorderStyle:None;
        ShowInTaskbar:False;
        StartPositon:CenterScreen.

posted @ 2009-11-22 00:42  网络金领  阅读(386)  评论(0编辑  收藏  举报