Display Start Up Picture
How can we show startup picture when my application starts as every software hows like Photoshop ,vs word etc?? I planed to past开发者_C百科e it on form and then show it but there is top blue bar coming that has controls etc any idea/
If you're looking for the simplest way, you can use the .NET Framework's excellent built-in support for splash screens. You'll have to put aside any irrational fears that you might have of including something with the name "Visual Basic" in a C# application, but this way will save you from having to roll your own custom solution and worry about things like multi-threading, invoking, and all that. It all compiles down to the same IL in the end anyway. Here's how it works:
Add a reference to
Microsoft.VisualBasic
to your project.Add a new form (named something like
SplashForm
) to serve as your splash screen.To make it look more like a proper splash screen, set the form's
FormBorderStyle
property to "None" and itsStartPosition
property to "CenterScreen". You can add any controls or images to this form that you want to be displayed on the splash screen to this form.Add the following code to your
Project.cs
file:using System; using System.Windows.Forms; using Microsoft.VisualBasic.ApplicationServices; namespace WindowsFormsApplication1 { static class Program { [STAThread] static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); new SplashScreenApp().Run(args); } } public class SplashScreenApp : WindowsFormsApplicationBase { protected override void OnCreateSplashScreen() { this.SplashScreen = new SplashForm(); this.SplashScreen.ShowInTaskbar = false; this.SplashScreen.Cursor = Cursors.AppStarting; } protected override void OnCreateMainForm() { //Perform any tasks you want before your application starts //FOR TESTING PURPOSES ONLY (remove once you've added your code) System.Threading.Thread.Sleep(2000); //Set the main form to a new instance of your form //(this will automatically close the splash screen) this.MainForm = new Form1(); } } }
If you want to do something fancy like create a transparent splash screen in the style of Adobe Photoshop, you can add an alpha-channel PNG image to your project's Resources file, and then add the following code to your splash screen form, replacing splashImage
with the path to your embedded image resource:
protected override void OnPaintBackground(PaintEventArgs pevent)
{
Graphics g = pevent.Graphics;
g.DrawImage(splashImage, new Rectangle(0, 0, this.Width, this.Height));
}
protected override void OnPaint(PaintEventArgs e)
{
//Do nothing here
}
For this to work, make sure that you have double buffering turned off, or else you'll get a black background to your form. There's really no reason to double buffer a splash screen anyway.
You can remove all those blue bars etc, via this.FormBorderStyle = FormBorderStyle.None
in your Form_Load()
.
So if I were you, I'd create a Form of specific Size, then set the following in Form_Load()
or directly in the code generated by the designer:
this.FormBorderStyle = FormBorderStyle.None;
this.StartPosition = FormStartPostition.CenterScreen;
Now you have a splash screen like many other apps - all you have to still do is write the code for all the making it visible or not stuff etc :)
WPF 3.5 and above actually has built in splash screen support, for faster rendering of the splash screen and much (much) less faffing with code. See this page for details.
Are you writing a WinForms or a WPF application? You will have to set different properties depending on which kind you write. If you are writing a WPF application, you can add the WindowStyle="None" and ResizeMode="NoResize" attributes to the Window top-level element in XAML. The first one will remove the title bar with the minimize, resize, and close buttons whereas the second one will remove the border around the form.
Now, you have a borderless form that you can modify to create a splash screen if you want or to simply add your startup image. If you don't want your default form to appear, you need to add Background="Transparent" and AllowsTransparency="True" attributes as well. The first one will set the background color to transparent whereas the second one allows your program to look transparent. Now, you can add any image in any shape, and the user will see only that image at program startup.
P.S. Make sure to load another form once the startup screen has been shown for a set amount of time or once the methods that are supposed to "load" stuff return control.
Pretty simple stuff!!
精彩评论