Initial Image Display

How can we show the initial image when my application starts, when each software is displayed as Photoshop, as well as a word, etc.? I planned to insert it into the form and then show it, but there is a top blue bar that has controls, etc. Any idea /

+6
c # visual-studio-2010
Dec 06 '10 at 9:27 a.m.
source share
5 answers

Do you really need a screensaver? There are many examples on the net, for example: http://www.codeproject.com/KB/cs/prettygoodsplashscreen.aspx

+4
Dec 06 '10 at 9:32
source share

If you're looking for the easiest way, you can use the excellent native .NET Framework support for splash screens. You need to discard any irrational fears that may arise including something called β€œVisual Basic” in a C # application, but this way saves you the trouble of minimizing your own custom solution and worrying about things like multithreading, calling, and all that. In any case, it all comes down to the same IL. Here's how it works:

  • Add a link to Microsoft.VisualBasic in your project.

  • Add a new form (named as SplashForm ) as your splash screen.

  • To make it look like a proper splash screen, set the FormBorderStyle property to "None" and its StartPosition property to "CenterScreen". You can add any controls or images to this form that you want to display on the splash screen in 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 like creating a transparent splash screen in the style of Adobe Photoshop, you can add an PNG image of an alpha channel to your project 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 you turn off double buffering, otherwise you will get a black background in your form. There really is no reason to double the splash screen buffer anyway.

+8
Dec 06 2018-10-12T00:
source share

You can remove all of these blue bars, etc. using this.FormBorderStyle = FormBorderStyle.None in Form_Load() .

So, if I were you, I would create a form of a certain size, and then set the following to 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 applications - all you have to do is write code for everything that makes it visible or not, etc. :)

+2
Dec 06 2018-10-12T00:
source share

WPF 3.5 and above are actually built-in to the screensaver, for faster rendering of the screensaver and a lot (much) less faffing with code. See this page for more details.

+1
Dec 06 '10 at
source share

Are you writing WinForms or a WPF application? You will need to set different properties depending on what kind you are writing. If you are writing a WPF application, you can add the WindowStyle = "None" and ResizeMode = "NoResize" attributes to the top-level Window element in XAML. The first one will delete the title bar using the "minimize", "resize" and "close" buttons, while the second will remove the frame around the form.

Now you have a borderless form that you can change to create a splash screen if you want, or just add your boot image. If you do not want your form to display by default, you need to add Background = "Transparent" and AllowsTransparency = "True". In the first case, the background color will be transparent, and the second transparent. Now you can add any image to any form, and the user will see only this image when the program starts.

PS Be sure to download another form after the launch screen is displayed for a set period of time or after the methods that are supposed to β€œload” return the control.

Pretty simple stuff!

0
Dec 06 2018-10-12T00:
source share



All Articles