Windows Mobile 开发界面之WelcomeForm->UserLoginForm->MainPanelForm


每个项目都会有一个主程序窗口,在客户端应用软件上更是如此。MainPanelForm 是主程序窗口,UserLoginForm是用户登录窗口,WelcomeForm是欢迎界面。

效果:

点击程序进入欢迎界面,欢迎界面一闪而逝,到登录界面,登录验证成功后跳转到主程序界面。将前两个窗体销毁。

主程序入口文件Program.cs如下(Main()方法在创建任何类或结构的实例前被调用,声明为static):

 static void Main() {
            //登录前初始化
            WelcomeForm wf = null;
            UserLoginForm loginForm = null;
            try {
				//欢迎界面
                wf = new WelcomeForm();
                wf.Show();
				
                //初始化公共UI对象
				........
                //初始化用户配置文件
				.........		
                //初始化版本信息
				.........
                //登录界面
                loginForm = new UserLoginForm();
                wf.Text = "";
                //关闭欢迎界面
                wf.Close();
                wf.Dispose();
                wf = null;
                loginForm.ShowDialog();
	    if (loginForm.IsLogin) {
		  loginForm.Dispose();
                    Application.Run(new MainPanelForm()); //主窗体 
                } else {
                    Application.Exit();
                }

            } catch (Exception ex) {
                DebugLog.fatal("[程序关闭]" + ex.ToString());
            } finally {
               
                    if (loginForm != null) {
                        loginForm.Close();
                        loginForm.Dispose();
                    }
                    if (wf != null) {
                        wf.Close();
                        wf.Dispose();
                    }
              
            }
        }

程序入口,首先显示WelcomeForm界面,初始化一些操作后(即间隔一段时间),跳转到登录界面,关闭欢迎界面资源。欢迎界面之后,验证通过,设置如下:

  isLogin = true;
  this.Close();

UserLoginForm静态变量isLogin是通过封装字段得到。

 Boolean isLogin = false;
        public Boolean IsLogin {
            get {
                return isLogin;
            }
            set {
                isLogin = value;
            }
        }

以上是由程序启动开始,欢迎界面->用户登录界面->主窗口界面的流程。

 补充:

前面说到Main()函数,如果想要在关闭窗口时关闭整个程序,Application.Exit();即可。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果您是在使用Windows窗体应用程序向导创建Windows桌面应用程序的话,可以通过以下步骤添加封面和进入下一步按钮: 1. 在“解决方案资源管理器”中,右键单击您的项目,选择“添加” > “新建项”。 2. 在“添加新项”对话框中,选择“Windows 窗体”。 3. 在“添加新项”对话框中,输入您想要的名称,例如“WelcomeForm”,然后单击“添加”。 4. 在“WelcomeForm.h”文件中添加以下代码: ```c++ #pragma once namespace YourAppName { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; /// <summary> /// Summary for WelcomeForm /// </summary> public ref class WelcomeForm : public System::Windows::Forms::Form { public: WelcomeForm(void) { InitializeComponent(); // //TODO: Add the constructor code here // } protected: /// <summary> /// Clean up any resources being used. /// </summary> ~WelcomeForm() { if (components) { delete components; } } private: System::Windows::Forms::Label^ label1; System::Windows::Forms::PictureBox^ pictureBox1; System::Windows::Forms::Button^ button1; #pragma region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> void InitializeComponent(void) { this->label1 = (gcnew System::Windows::Forms::Label()); this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox()); this->button1 = (gcnew System::Windows::Forms::Button()); (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit(); this->SuspendLayout(); // // label1 // this->label1->AutoSize = true; this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 18, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0))); this->label1->Location = System::Drawing::Point(73, 34); this->label1->Name = L"label1"; this->label1->Size = System::Drawing::Size(263, 29); this->label1->TabIndex = 0; this->label1->Text = L"Welcome to Your App"; // // pictureBox1 // this->pictureBox1->Image = global::YourAppName::Resources::logo; this->pictureBox1->Location = System::Drawing::Point(78, 85); this->pictureBox1->Name = L"pictureBox1"; this->pictureBox1->Size = System::Drawing::Size(250, 250); this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage; this->pictureBox1->TabIndex = 1; this->pictureBox1->TabStop = false; // // button1 // this->button1->Location = System::Drawing::Point(153, 360); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(100, 40); this->button1->TabIndex = 2; this->button1->Text = L"Next"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &WelcomeForm::button1_Click); // // WelcomeForm // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(400, 450); this->Controls->Add(this->button1); this->Controls->Add(this->pictureBox1); this->Controls->Add(this->label1); this->Name = L"WelcomeForm"; this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen; this->Text = L"Your App"; (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit(); this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { this->Close(); } }; } ``` 5. 在“WelcomeForm.h”文件的`#pragma endregion`前添加以下代码: ```c++ #include "resources.h" ``` 6. 在“解决方案资源管理器”中,右键单击您的项目,选择“添加” > “现有项”。 7. 在“添加现有项”对话框中,选择您想要添加的图片和资源文件。 8. 在“WelcomeForm.h”文件中添加以下代码: ```c++ #include "resources.h" ``` 9. 在资源视图中,右键单击您的项目,选择“添加” > “资源文件”。 10. 在“添加新项”对话框中,选择“图标”,然后单击“添加”。 11. 在“New Icon”对话框中,选择您想要的图标文件。 12. 在“资源视图”中,双击“图标”,然后选择您想要的图标大小和颜色。 13. 在“WelcomeForm.h”文件中添加以下代码: ```c++ this->Icon = gcnew System::Drawing::Icon(L"YourAppIcon.ico"); ``` 14. 在您的应用程序主函数中添加以下代码: ```c++ using namespace YourAppName; int main(array<System::String ^> ^args) { Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); WelcomeForm^ welcomeForm = gcnew WelcomeForm(); welcomeForm->ShowDialog(); return 0; } ``` 现在,当您的应用程序启动时,将会显示欢迎窗体。当用户点击“下一步”按钮时,窗体将会自动关闭。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值