您的位置:首页 > 其它

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

2015-09-11 09:24 218 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: