Afn*_*hir 6 c# visual-studio-2010
当我的应用程序启动时,我们怎样才能显示启动图片,因为每个软件如Photoshop,vs word等?我计划将它粘贴在表格上,然后显示它,但有顶部蓝色条,有控制等任何想法/
如果您正在寻找最简单的方法,您可以使用.NET Framework对启动屏幕的出色内置支持.你不得不抛开任何非理性的恐惧,你可能会在C#应用程序中包含一些名为"Visual Basic"的东西,但这样可以避免你不得不推出自己的自定义解决方案并担心像线程,调用等等.无论如何,这一切都归结为同样的IL.以下是它的工作原理:
添加Microsoft.VisualBasic对项目的引用.
添加一个新表单(类似名称SplashForm)作为启动画面.
要使其看起来更像正确的启动画面,请将窗体的FormBorderStyle属性设置为"无",将其StartPosition属性设置为"CenterScreen".您可以将任何控件或图像添加到此表单,以便在启动屏幕上显示此表单.
将以下代码添加到您的Project.cs文件中:
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();
          }
       }
    }
如果你想做一些像 Adobe Photoshop 一样创建透明闪屏的想法,可以将alpha通道PNG图像添加到项目的Resources文件中,然后将以下代码添加到启动画面窗体中,替换splashImage为嵌入式图像资源的路径:
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
}
为此,请确保关闭双缓冲,否则您将获得表单的黑色背景.无论如何,没有理由双重缓冲启动画面.
您可以通过this.FormBorderStyle = FormBorderStyle.None在您的Form_Load().
因此,如果我是你,我会创建一个特定大小的表单,然后在设计器生成的代码中Form_Load()
或直接在设计器生成的代码中设置以下内容:
this.FormBorderStyle = FormBorderStyle.None;
this.StartPosition = FormStartPostition.CenterScreen;
现在你有一个像许多其他应用程序一样的启动屏幕 - 你所要做的就是编写所有使其可见或不可见的代码等:)