显示启动图片
您可以通过Form_Load()
中的this.FormBorderStyle = FormBorderStyle.None
删除所有这些蓝条等。
所以,如果我是你,我会创建特定大小的表格,然后设置在由设计器生成的代码Form_Load()
或者直接在下面:
this.FormBorderStyle = FormBorderStyle.None;
this.StartPosition = FormStartPostition.CenterScreen;
现在你有一个闪屏像许多其他应用程序 - 所有你仍然要做的是编写所有的代码,使其可见或不是东西等:)
你正在写一个WinForms或WPF应用程序吗?您将不得不根据您编写的类型设置不同的属性。如果您正在编写WPF应用程序,则可以将WindowStyle =“None”和ResizeMode =“NoResize”属性添加到XAML中的Window顶层元素。第一个将使用最小化,调整大小和关闭按钮删除标题栏,而第二个将删除表单的边框。
现在,您拥有无边框窗体,您可以修改该窗体以创建启动画面,或者只需添加启动图像。如果您不希望显示默认窗体,则还需要添加Background =“Transparent”和AllowsTransparency =“True”属性。第一个将背景颜色设置为透明,而第二个则允许您的程序看起来透明。现在,您可以添加任何形状的图像,并且用户将在程序启动时仅看到该图像。
P.S.一旦启动屏幕显示一段时间,或者应该“加载”东西的方法返回控制,请务必加载另一个表单。
很简单的东西!
如果您正在寻找最简单的方法,那么您可以使用.NET Framework优秀的内置支持启动屏幕。您必须抛开任何非理性的担忧,您可能会在C#应用程序中包含名为“Visual Basic”的东西,但这样可以帮助您避免必须推出自己的定制解决方案,并担心诸如多线程,调用等等。无论如何,它最终都会编译到相同的IL。以下是它的工作原理:
将对
Microsoft.VisualBasic
的引用添加到项目中。添加一个新表单(名称类似于
SplashForm
)作为您的启动画面。为了使它看起来更像是一个合适的启动画面,请将窗体的
FormBorderStyle
property设置为“无”,将其StartPosition
property设置为“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
}
对于这项工作,确保您有双缓冲关断,否则你会得到一个黑色背景的形式。无论如何,真的没有理由加倍缓冲闪屏。
不要忘记在程序中加入一个选项来关闭启动屏幕,您的用户会爱上它! – 2010-12-06 09:39:09
只是不要让你的启动画面最顶级。我讨厌的应用程序,我不能退出,因为他们坚持他们的启动画面保持可见,直到应用程序终于加载。 – JLWarlow 2010-12-06 10:12:14
WPF或WinForms? – 2010-12-06 10:31:46