共用方式為


Splash Screen on Pocket PC

Sometimes it would be nice to add a splash screen to your Pocket PC application. You can show your company logo, product title, product logo as well as other information on the splash screen. On .NET Framework, you may use two Application.Run() calls, passing the splash screen form to the first call and the main form to the second call. On .NET Compact Framework, since you cannot do more than one Application.Run() call on one thread, the splash screen form needs to be called by the main form. We are going to illustrate how this can be done in a sample application.

The application consists of two forms, one for the splash screen and the other for the main form. When the application is run, the splash screen is shown full-screen with the text ".NET Compact Framework" at the center of the screen. After 3 seconds, the splash screen form is closed and the main form is shown.

Here are the codes for the application:

 using System;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

class Form1 : System.Windows.Forms.Form
{
    public Form1()
    {
        this.MinimizeBox = false;
        Form2 form = new Form2();
        form.ShowDialog();
    }

    static void Main()
    {
        Application.Run(new Form1());
    }
}

public class Form2 : System.Windows.Forms.Form
{
    public Form2()
    {
        this.FormBorderStyle = FormBorderStyle.None;
        this.WindowState = FormWindowState.Maximized;
        this.TopMost = true;
        this.BackColor = Color.Green;
        Timer timer = new Timer();
        timer.Interval = 3000;
        timer.Tick += new EventHandler(timer_Tick);
        timer.Enabled = true;
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        StringFormat sf = new StringFormat();
        sf.Alignment = StringAlignment.Center;
        sf.LineAlignment = StringAlignment.Center;
        Graphics g = e.Graphics;
        g.DrawString(".NET Compact Framework", this.Font, new SolidBrush(Color.Blue), Screen.PrimaryScreen.Bounds, sf);
    }

    void timer_Tick(object o, EventArgs e)
    {
        this.Close();
    }
}

Cheers,

Anthony

This posting is provided "AS IS" with no warranties, and confers no rights.

Comments