用 .NET制作程序启动画面的两种方法。
启动画面程序很容易,主要 用于程序各个模块的加载,给出用户交互的信息。以前用delphi写启动换面程序很容易,而.net不是那么容易上手,经过学习和实验,目前掌握了两种.net制作启动画面的方法,现在写出来供大家参考,希望能对初写着有所帮助,也希望高手提出更好的办法。
以下程序采用(vc++.net2003)编写。
1、采用线呈阻止方法。
#pragma once
#include "splash.h"
#include "formlogin.h"
namespace sunsoft
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Threading;
/// <summary>
/// Form1 摘要
///
/// 警告: 如果您更改该类的名称,则需要更改
/// 与该类所依赖的所有 .resx 文件关联的托管资源编译器工具的
/// “资源文件名”属性。 否则,
/// 设计器将不能与此窗体关联的
/// 本地化资源正确交互。
/// </summary>
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
bzjy * mybzjy = new bzjy();
mybzjy->Hide();
splash * mysplash = new splash();
mysplash->Show();
mysplash->Update();
mysplash->progressBar1->Maximum=20;
mysplash->progressBar1->Minimum=0;
for (int i=0;i<20;i++)
{
mysplash->progressBar1->Value=i;
Thread::Sleep(100);
}
mysplash->Hide();
formlogin * myformlogin = new formlogin();
myformlogin->ShowDialog();
}
2、在启动主窗口前加载启动窗口。
#include "stdafx.h"
#include "Form1.h"
#include <windows.h>
using namespace sunsoft;
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA;
Application::Run(new Form2());//启动窗口
Application::Run(new Form1());//主窗口
Application::EnableVisualStyles();
return 0;
}
在第二种方法中,要在loadform中设置判断窗口关闭的事件代码。在此略。
以上两种方法:第一种方法适合大程序的加载。第二种方法适合下程序制作封面。
写到这吧!syszero 2006年10月26日。