zoukankan      html  css  js  c++  java
  • .NET基础示例系列之七:登录窗口

    WinForm程序常常需要制作登录窗口,如果登录过程较复杂,所需时间较久,有时还需要在登录过程中显示一些进度信息,以下是一个简单的示例:

    新建两个窗体,分别作为登录窗体、主窗体,现在重点在登录窗体:

    添加必要的标签、文本框,两个按钮,以及一个用于显示状态的标签:lbState

    设置窗体的acceptbuttoncancelbutton分别为btOKbtCancel,使窗体可以响应Enter键和Esc键。设置btCancelDialogResultCancel

    btOK的点击事件中:

    private void btOK_Click(object sender, EventArgs e)

    {

        this.lbState.Text = "用户验证......";

        Application.DoEvents();//处理当前在消息队列中的所有windows消息,避免出现界面假死现象

        if (!UserCheck(this.tbName.Text, this.tbPwd.Text))

        {

            this.lbState.Text = "";

            MessageBox.Show("用户名或密码错误!", "错误");

            this.tbName.Focus();

        }

        else

        {

            this.lbState.Text = "连接DCOM......";

            Application.DoEvents();//

            if (!ConnectDCOM())

            {

                this.lbState.Text = "";

                MessageBox.Show("连接DCOM出现错误,程序无法启动!", "错误");

            }

            else

            {

                this.DialogResult = DialogResult.OK;

            }

        }

    }

     

    private bool UserCheck(string userName,string userPwd)

    {

    //TO DO:USER CHECK

    }

     

    private bool ConnectDCOM()

    {

    // TO DO:CONNECT DCOM

    }

     

    程序入口处:

    static void Main()

    {

        Application.EnableVisualStyles();

        Application.SetCompatibleTextRenderingDefault(false);

     

        LoginForm lf = new LoginForm();

        if (lf.ShowDialog() == DialogResult.OK)

        {

            Application.Run(new MainForm());

        }

    }

  • 相关阅读:
    第2季:从官方例程深度学习海思SDK及API
    H.264帧结构详解
    Linux内核链表
    在Sqlite中通过Replace来实现插入和更新
    mysql 里随机生成时间
    搭建Cordova + Ionic + WebStorm环境开发Web App应用
    Angular Local Storage 使用方法
    angularJS中controller与directive双向通信
    ui-router传递参数
    Sequelize 和 MySQL 对照
  • 原文地址:https://www.cnblogs.com/morvenhuang/p/500158.html
Copyright © 2011-2022 走看看