启动画面的停滞时间有timer的interval值来控制。form1的startposition属性为centerscreen,formborderstyle为none.

解决方案 »

  1.   

    Form1 MainForm = new Form1();
    Form2 WelcomeForm = new Form2();
    WelcomeForm.Show();
    System.Threading.Thread.Sleep(10000);
    WelcomeForm.Close();
    Application.Run(MainForm);简单的就这样MainForm中如果在Load时有大量数据处理就需要单独处理
      

  2.   

    tryForm1:
    ----------------------------------------------
    private void timer1_Tick(object sender, System.EventArgs e)
    {
    timer1.Enabled = false;
    this.Close();
    } private void Form1_Load(object sender, System.EventArgs e)
    {
    timer1.Enabled = true;
    }
    ----------------------------------------------
    Form2:---------------------------------------------
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Form1 f1 = new Form1();
    f1.ShowDialog();
    Application.Run(new Form2());
    }
      

  3.   

    同意:iyond(伊飏)和commandown(它山之石) 我的做法
    [STAThread]
    static void Main() 
    {
           //加载启动画面
           frmFlash cmicFrm;
           cmicFrm=new frmFlash();
           //加载信息
          ......
           
           Application.Run();
           //关闭启动画面
           cmicFrm.Close();
           //加载主窗体
           frmMain cmicFrmMain;
           cmicFrmMain=new frmMain();
    }
      

  4.   

    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Threading;namespace XXXXX.Library.Forms
    {
    public sealed class SplashScreen
    {
        static SplashForm m_SplashForm;
        static Thread m_WorkerThread;    private SplashScreen()
        {
        }    static SplashScreen()
        {
            m_SplashForm = new SplashForm();
            //在我的库中有一个 BMP 图象资源作为默认图象
            m_SplashForm.SplashImage = Resources.bmpSplash;
        }    public static Image SplashImage
        {
            get
            {
                return m_SplashForm.SplashImage;
            }
            set 
            {
                m_SplashForm.SplashImage = value;
            }
        }    public static string InfoText 
        {
            get 
            {
                return m_SplashForm.InfoText;
            }
            set 
            {
                m_SplashForm.InfoText = value;
            }
        } public static void Show(Bitmap splashImage)
        {
            if (splashImage == null)
                throw new ArgumentNullException();        m_SplashForm.SplashImage = splashImage;
            Show();
        }
    public static void Show()
        {
            ThreadStart threadStart = new ThreadStart(ShowForm);
    m_SplashForm.HideSplash = false;
            m_WorkerThread = new Thread(threadStart);
            m_WorkerThread.Start();
        }    public static void Close()
        {
    if (m_SplashForm != null && !m_SplashForm.IsDisposed)
    m_SplashForm.HideSplash = true;
            // 这一句调试用
            //m_WorkerThread.Join();
        }
        public static void Dispose()
        {
    if (m_SplashForm != null)
    m_SplashForm.Dispose();
    m_SplashForm = null;
        }
    }
      

  5.   

    // 这是一个实际显示的窗体,不能由外部创建,只能由 SplashScreen 来创建。
    internal class SplashForm : Form
    {
        private System.Windows.Forms.Timer timer1;
        private PictureBox m_SplashPictureBox;
        private System.ComponentModel.IContainer components;
        private bool m_HideSplash = false;
        private System.Windows.Forms.Timer timer2;
    private Point orgPoint;    internal System.Windows.Forms.Label InfoLabel;
        
        public SplashForm()
        {
            InitializeComponent();
            this.timer1.Start();
        }
    #region Windows Form Designer generated code
        private void InitializeComponent()
        {
    this.components = new System.ComponentModel.Container();
    this.m_SplashPictureBox = new System.Windows.Forms.PictureBox();
    this.timer1 = new System.Windows.Forms.Timer(this.components);
    this.InfoLabel = new System.Windows.Forms.Label();
    this.timer2 = new System.Windows.Forms.Timer(this.components);
    this.SuspendLayout();
    // 
    // m_SplashPictureBox
    // 
    this.m_SplashPictureBox.Cursor = System.Windows.Forms.Cursors.AppStarting;
    this.m_SplashPictureBox.Name = "m_SplashPictureBox";
    this.m_SplashPictureBox.Size = new System.Drawing.Size(112, 80);
    this.m_SplashPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
    this.m_SplashPictureBox.TabIndex = 0;
    this.m_SplashPictureBox.TabStop = false;
    this.m_SplashPictureBox.Click += new System.EventHandler(this.m_SplashPictureBox_Click);
    this.m_SplashPictureBox.MouseUp += new System.Windows.Forms.MouseEventHandler(this.OnMouseUp);
    this.m_SplashPictureBox.MouseMove += new System.Windows.Forms.MouseEventHandler(this.OnMouseMove);
    this.m_SplashPictureBox.MouseDown += new System.Windows.Forms.MouseEventHandler(this.OnMouseDown);
    // 
    // timer1
    // 
    this.timer1.Enabled = true;
    this.timer1.Interval = 500;
    this.timer1.Tick += new System.EventHandler(this.OnTick);
    // 
    // InfoLabel
    // 
    this.InfoLabel.BackColor = System.Drawing.Color.Aqua;
    this.InfoLabel.Cursor = System.Windows.Forms.Cursors.Default;
    this.InfoLabel.Dock = System.Windows.Forms.DockStyle.Bottom;
    this.InfoLabel.Location = new System.Drawing.Point(0, 286);
    this.InfoLabel.Name = "InfoLabel";
    this.InfoLabel.Size = new System.Drawing.Size(415, 19);
    this.InfoLabel.TabIndex = 1;
    this.InfoLabel.Text = "Loading ...";
    this.InfoLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
    this.InfoLabel.MouseUp += new System.Windows.Forms.MouseEventHandler(this.OnMouseUp);
    this.InfoLabel.MouseMove += new System.Windows.Forms.MouseEventHandler(this.OnMouseMove);
    this.InfoLabel.MouseDown += new System.Windows.Forms.MouseEventHandler(this.OnMouseDown);
    // 
    // timer2
    // 
    this.timer2.Interval = 2000;
    this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
    // 
    // SplashForm
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(415, 305);
    this.ControlBox = false;
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.m_SplashPictureBox, 
      this.InfoLabel});
    this.Cursor = System.Windows.Forms.Cursors.Cross;
    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
    this.Name = "SplashForm";
    this.ShowInTaskbar = false;
    this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
    this.TopMost = true;
    this.ResumeLayout(false); }
    #endregion    // 这一 timer1 的处理方法,是检测是否要隐藏启动画面。
        // 如果要隐藏启动画面,则停止 timer1,并启动 timer2。
        // 实际的隐藏处理操作,由 timer2 的 Tick 事件来完成。
        private void OnTick(object sender, EventArgs e)
        {
            if(HideSplash == true)
            {
                this.timer1.Enabled = false;
                this.timer2.Enabled = true;
            }
        }    // 加载结束并继续停留时,用户单击启动画面,能够立即关闭启动画面。
        private void m_SplashPictureBox_Click(object sender, System.EventArgs e)
        {
            if (this.timer1.Enabled == false)
            {
                this.timer2.Stop();
                this.timer1.Dispose();
                this.timer2.Dispose();
                this.m_SplashPictureBox.Dispose();
            
                this.Close();
            }
        }
             // 以下几个鼠标事件处理方法用于移动启动窗体
    private void OnMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    this.Cursor = Cursors.SizeAll;
    orgPoint = new Point(e.X, e.Y);
    orgPoint = this.PointToScreen(orgPoint);
    } private void OnMouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    this.Cursor = Cursors.Default;
    } private void OnMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if(e.Button==MouseButtons.Left)
    {
    Point tp = new Point(e.X, e.Y);
    tp = this.PointToScreen(tp);
    this.Top += tp.Y -orgPoint.Y;
    this.Left += tp.X-orgPoint.X;
    this.orgPoint = tp;
    }
    }
       // 这一个方法用于处理加载结束后,在屏幕上继续停留多久
        private void timer2_Tick(object sender, System.EventArgs e)
        {
            this.timer2.Stop();
            this.timer1.Dispose();
            this.timer2.Dispose();
            this.m_SplashPictureBox.Dispose();
            this.Close();
        }    // 是否要隐藏启动画面
        // 当这个值为 true 时,还不一定马上隐藏,继续停留的时间视 timer2 的设置。
        public bool HideSplash
        {
            get
            {
                return m_HideSplash;
            }
            set
            {
                lock(this)
                {
                    m_HideSplash = value;   
                }
            }
        }    // 设置显示在启动画面下方面的加载信息文本。
        public string InfoText
        {
            get
            {
                lock(this)
                {
                    return this.InfoLabel.Text;
                }
            }
            set
            {
                lock(this)
                {
                    this.InfoLabel.Text = value;   
                }
            }
        }    // 设定实际使用的图象
        public Image SplashImage
        {
            get
            {
                return this.m_SplashPictureBox.Image;
            }
            set 
            {
                if (m_SplashPictureBox.Image == value)
                    return;
                m_SplashPictureBox.Image = value;
                this.ClientSize = new Size(m_SplashPictureBox.Size.Width, 
                    m_SplashPictureBox.Size.Height + this.InfoLabel.Height);
            }
        }}
    }
      

  6.   

    在开始加载时,使用如下代码:
      // 初始化启动画面
      XXXXXX.Library.Forms.SplashScreen.SplashImage = ...;
      XXXXXX.Library.Forms.SplashScreen.InfoText = ...;
      // 显示欢迎画面
      XXXXXX.Library.Forms.SplashScreen.Show();在加载过程中,可以动态刷新加载信息。
      XXXXXX.Library.Forms.SplashScreen.InfoText = ...;在加载结束后,使用以下代码关闭启动画面:
      XXXXXX.Library.Forms.SplashScreen.InfoText = ; //加载结束信息,如“Ready”
      XXXXXX.Library.Forms.SplashScreen.Close();注意调用 Close 方法后,并不一定马上会关闭启动画面,启动画面还会继续停留一段时间,这个时间视楼上帖中 timer2 设置,我的设置为 2000 ms(2 秒钟)。但停留时,用户单击启动画面,能够立即关闭。这是我个人的实现,肯定还有更好的方式,此例仅供一起探讨。
      

  7.   

    我来已经结帖了。我的处理方法是:1——
    定义一个Form,用作启动窗口,在这个窗口上提供若干接口函数和属性,用于设置相关提示信息等。2——
    在程序启动的时候,创建这个启动窗口,同时创建一个线程,线程的处理函数只是简单的把启动窗口以DIALOG的形式显示3——
    启动线程,这样就显示了启动窗口了。4——
    启动窗口启动后(线程启动后),主程序继续运行,在主程序中根据需要调用启动窗口的方法或属性设置在启动窗口变化的动态信息5——
    当主程序初始化启动完成后,关闭启动窗口,退出线程(可以显式调用也可以不调用,因为关闭了启动窗口会自动退出的,反过来,退出了线程,由线程启动的启动窗口也会自动关闭)这里要注意的一点是,当关闭启动窗口后,主窗口可能不能获得窗口,可以通过ACTIVATE方法来激活。上面的方法是临时的。最好的办法是应该实现一个封装了的启动窗口,过断时间再整理了。
      

  8.   

    sorry,大象的方法我没有试,就说了行,主要原因是以前用pb里就是这样的,我以为C#里这样也应该行,犯了低级错误。在此表示歉意!
      

  9.   

    对。
    如果用大象的方法,启动窗口必须是SHOW的,而不能是SHOWDIALOG的,而且启动窗口启动以后,启动窗口会出现类似马赛克的东西。不过我的方法,我也发现一个问题,就是动态显示的信息有时会动态变化,有时又不变化,不知道是否我的应用问题还是这个解决方案问题。分析起来,这个解决方案应该是没有问题的。
      

  10.   

    还是另外开个线程的好,我想上面triout出现的问题可能和这个有关,用线程的话就不会有这个问题。
      

  11.   

    参考了codeproject上的一个demo,他也是采用线程的,做的不错。
    http://www.codeproject.com/csharp/apploadingarticle.asp?target=splashForm