注:转载至http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=406
Splash screens can easily provide a professional look to a program and allow startup code to run in the background. Especially when using web services, it can take time to contact the web service and get an instance of it instantiated. Instead of making the user stare at blank windows until the program is ready, why not show a splash screen with a text display showing the progress? This tutorial is written in C#, but of course the principle can be applied in just about any programming language.
1. Create the Project
First, create a new project to demonstrate the splash screen. The form in this project will be the startup form for the project. I'll refer to this main form as Form1.
2. Splash Form
The splash form is a regular Windows Form with no border or title bar. Add a new form to the project called frmSplash.cs. Set the following properties of the form:
FormBorderStyle = None
Modifiers = Public
StatPosition = CenterScreen
Next, add a label to the form and name it lblStatus. Eventually it will be a good idea to add a logo to the form and make the label blend in by setting the backcolor to match the image and by setting the font color. For now we'll just focus on the code.
3. Main Form Code
In the load method for Form1, add the following code to control the splash screen:
That's all there is to it. It's a very simple way to add that professional touch to your programs while getting some time consuming code out of the way up front.
Splash screens can easily provide a professional look to a program and allow startup code to run in the background. Especially when using web services, it can take time to contact the web service and get an instance of it instantiated. Instead of making the user stare at blank windows until the program is ready, why not show a splash screen with a text display showing the progress? This tutorial is written in C#, but of course the principle can be applied in just about any programming language.
1. Create the Project
First, create a new project to demonstrate the splash screen. The form in this project will be the startup form for the project. I'll refer to this main form as Form1.
2. Splash Form
The splash form is a regular Windows Form with no border or title bar. Add a new form to the project called frmSplash.cs. Set the following properties of the form:
Next, add a label to the form and name it lblStatus. Eventually it will be a good idea to add a logo to the form and make the label blend in by setting the backcolor to match the image and by setting the font color. For now we'll just focus on the code.
3. Main Form Code
In the load method for Form1, add the following code to control the splash screen:
private void Form1_Load(object sender, System.EventArgs e) { // Display the splash screen frmSplash SplashScreen = new frmSplash(); SplashScreen.Show() // show the splash form and update text as events occur SplashScreen.lblStatus.Text = "Helpful information here"; SplashScreen.lblStatus.Refresh(); // call the method to perform the action // Repeat the update of the text and calling methods until program is ready to run. // Close the splash screen SplashScreen.Close() } |
That's all there is to it. It's a very simple way to add that professional touch to your programs while getting some time consuming code out of the way up front.