首页 > Windows开发 > 详细

winform中Load事件和shown事件以及自动登陆的实现

时间:2015-09-11 10:21:36      阅读:1241      评论:0      收藏:0      [点我收藏+]

winform中load事件是窗体加载的时候执行的时间。在执行的时候,窗体还没显示出来。而Shown事件窗体已经显示出来,控件加载完成,需要注意的是:如果控件设置了背景图片,那么控件的背景颜色是不显示的。如果做自动登陆,需要窗体显示完成显示几秒。可以用Timer控件。而不是在shown中暂停线程。

 

#region 窗体加载时如果记住密码,加载密码、用户名;如果自动登录,窗体加载成功后,2s执行自动登录
        /// <summary>
        /// 窗体加载时如果记住密码,加载密码、用户名;如果自动登录,窗体加载成功后,2s执行自动登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Login_Load(object sender, EventArgs e)
        {
            if (getIsRemberPassword())
            {
                this.txt_UserName.Text = getUserNameByXml();
                this.txt_Password.UseSystemPasswordChar = true;
                this.txt_Password.Text = getUserPasswordByXml();
                this.chk_RemberPwd.Checked = true;
            }
            if (getIsAutoLogin())
            {
                this.chk_AutoLogin.Checked = true;
                this.chk_RemberPwd.Enabled = false;
                System.Timers.Timer timer_Login = new System.Timers.Timer(500);
                timer_Login.Elapsed += timerLogin;
                timer_Login.AutoReset = false;
                timer_Login.Enabled = true;
            }

        }
        #endregion

        #region 自动登录事件
        /// <summary>
        /// 自动登录事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void timerLogin(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (userlogin() > 0)
            {
                this.DialogResult = DialogResult.OK;
            }
        }
        #endregion


 

winform中Load事件和shown事件以及自动登陆的实现

原文:http://www.cnblogs.com/jolab/p/4799962.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!