VB.Net程序设计:最简单的初始屏幕(程序启动画面)
2008-04-02 10:59
459 查看
做一个系统,打开系统时候要加载和检测一些数据。想到要用像打开Photoshop那样有一个初始屏幕,有提示加载数据情况。感觉很棒。在网上找了许多代码。那些感觉都是特别复杂。或用到事件委托,或消息机制,或单独进程等等。在CodeProject网站上也有一篇比较好和简单的关于初始屏幕的文章。 见文章最后。
自己就开始做一个。
在你的项目里面,新建一个窗体:FlashScn.vb(名字随便)作为程序启动画面。背景可以是图片,标题上面可以放公司的logo。里面最少要有一个label控件来显示程序运行情况。
设置窗体的属性:
FormBorderStyle = None
Modifiers = Public (Modifiers 属性是指定给该成员变量的访问修饰符。因为我们创建的FlashScn窗体是不是组件或控件,找不到这个属性。可以不设置或不管他。)
StatPosition = CenterScreen
界面如:
主要把程序启动画面加入到你的MainFrm_Load(主窗体的Load事件)中,代码如下:
Private Sub MainFrm_Load()Sub MainFrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim fs As New FlashScn
fs.Show()
fs.LB.Text = "开始加载程序..."
'插入加载你的数据的代码....
fs.Refresh()
System.Threading.Thread.Sleep(1000) '插入你的代码后,这个可以去掉。
fs.LB.Text = "设置连接数据库字符串..."
'插入你设置的代码...
fs.Refresh()
System.Threading.Thread.Sleep(1000)
fs.LB.Text = "检测数据和数据库连接情况..."
'插入你检测数据和连接数据库情况的代码...
fs.Refresh()
System.Threading.Thread.Sleep(1000)
fs.LB.Text = "系统检测完毕."
fs.Refresh()
System.Threading.Thread.Sleep(1000)
fs.Close()
End Sub
完成后。注意在项目的启动窗体设置为:MainFrm(主窗体)。
按F5,运行了。程序的启动画面也出来了。感觉不错。呵呵。
Win2K+VS2005
CodeProject的文章:
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:
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()
}
自己就开始做一个。
在你的项目里面,新建一个窗体:FlashScn.vb(名字随便)作为程序启动画面。背景可以是图片,标题上面可以放公司的logo。里面最少要有一个label控件来显示程序运行情况。
设置窗体的属性:
FormBorderStyle = None
Modifiers = Public (Modifiers 属性是指定给该成员变量的访问修饰符。因为我们创建的FlashScn窗体是不是组件或控件,找不到这个属性。可以不设置或不管他。)
StatPosition = CenterScreen
界面如:
主要把程序启动画面加入到你的MainFrm_Load(主窗体的Load事件)中,代码如下:
Private Sub MainFrm_Load()Sub MainFrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim fs As New FlashScn
fs.Show()
fs.LB.Text = "开始加载程序..."
'插入加载你的数据的代码....
fs.Refresh()
System.Threading.Thread.Sleep(1000) '插入你的代码后,这个可以去掉。
fs.LB.Text = "设置连接数据库字符串..."
'插入你设置的代码...
fs.Refresh()
System.Threading.Thread.Sleep(1000)
fs.LB.Text = "检测数据和数据库连接情况..."
'插入你检测数据和连接数据库情况的代码...
fs.Refresh()
System.Threading.Thread.Sleep(1000)
fs.LB.Text = "系统检测完毕."
fs.Refresh()
System.Threading.Thread.Sleep(1000)
fs.Close()
End Sub
完成后。注意在项目的启动窗体设置为:MainFrm(主窗体)。
按F5,运行了。程序的启动画面也出来了。感觉不错。呵呵。
Win2K+VS2005
CodeProject的文章:
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:
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()
}
相关文章推荐
- HOW TO:溅射屏幕(Splash Screen),也叫程序启动画面的制作(.NET2003)
- 溅射屏幕(Splash Screen),也叫程序启动画面的制作
- HOW TO:溅射屏幕(Splash Screen),也叫程序启动画面的制作(.NET2005)
- HOW TO:溅射屏幕(Splash Screen),也叫程序启动画面的制作(.NET2003)
- [Android]Delphi/C++ Builder 开发 Android 程序启动画面简单完美解决方案
- Delphi开发 Android 程序启动画面简单完美解决方案
- HOW TO:溅射屏幕(Splash Screen),也叫程序启动画面的制作(.NET2003)
- HOW TO:溅射屏幕(Splash Screen),也叫程序启动画面的制作(.NET2005)
- 插入动画及程序启动画面
- SendMessage 启动屏幕保护程序
- Android程序启动时的加载画面Demo
- android程序启动画面之Splash总结
- 鉴客 android程序启动画面之Splash总结
- iPhone、iPhone4、iPad 程序启动画面的总结
- 当程序启动时,保持屏幕变暗状态
- IOS开发8---APP应用程序图标 及 程序启动画面设置。
- 用VC创建程序启动画面
- 给程序添加启动画面(C#.net )
- Qt学习16——程序启动画面QSplashScreen
- QSplashScreen程序启动画面