淘先锋技术网

首页 1 2 3 4 5 6 7


 本代码可以依据主程序加载进度来显示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.

本文来源于Woody的鸟窝(Woody's Blog) http://www.smartgz.com, 原文地址:http://www.smartgz.com/blog/Article/1088.asp

转载于:https://www.cnblogs.com/dg123/archive/2009/05/13/1456244.html