WinForm登录模块设计开发
生活随笔
收集整理的這篇文章主要介紹了
WinForm登录模块设计开发
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
用戶登錄類:
public partial class UserLogin : DevComponents.DotNetBar.Office2007RibbonForm
{
private SceneViewer sceneViewer = new SceneViewer();
private UserManage userManage = new UserManage();
public UserLogin()
{
InitializeComponent();
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
//MessageBox.Show("請輸入正確的用戶名和密碼!", "登陸失敗!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
private void btnLogin_Click(object sender, EventArgs e)
{
if (this.editUserName.Text == string.Empty)
{
MessageBox.Show("用戶名不能為空!");
this.editUserName.Focus();
return;
}
else if(userManage.UserDictionary.ContainsKey(this.editUserName.Text))
{
string psd = userManage.UserDictionary[this.editUserName.Text];
if (this.editPassword.Text == psd)
{
MessageBox.Show("歡迎登錄本系統!", "登陸成功!", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.DialogResult = DialogResult.OK;
}
else
{
MessageBox.Show("密碼錯誤,請重新輸入!", "密碼錯誤!", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.editPassword.Text = string.Empty;
this.editPassword.Focus();
}
}
else
{
MessageBox.Show("用戶名不存在!","登錄失敗!",MessageBoxButtons.OK,MessageBoxIcon.Warning);
this.editUserName.Text = string.Empty;
this.editPassword.Text = string.Empty;
this.editUserName.Focus();
}
}
private void btnLogin_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
this.btnLogin.Click+=new EventHandler(btnLogin_Click);
}
}
private void UserLogin_Load(object sender, EventArgs e)
{
if (this.editUserName.Text == string.Empty && this.editPassword.Text == string.Empty)
{
this.btnLogin.Enabled = false;
}
}
private void editPassword_TextChanged(object sender, EventArgs e)
{
if (this.editUserName.Text == string.Empty && this.editPassword.Text == string.Empty)
this.btnLogin.Enabled = false;
else if (this.editUserName.Text == string.Empty && this.editPassword.Text != string.Empty)
this.btnLogin.Enabled = false;
else if (this.editUserName.Text != string.Empty && this.editPassword.Text == string.Empty)
this.btnLogin.Enabled = false;
else
this.btnLogin.Enabled = true;
}
}
?
主程序類:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
UserLogin userLogin = new UserLogin();
try
{
if (userLogin.ShowDialog() == DialogResult.OK)
Application.Run(new SceneViewer());
else
Application.Exit();
}
finally
{
userLogin.Close();
}
}
}
?
至于用戶的管理,若用戶數量很少,且內部使用可以用Dictionary<key,value>進行管理;
若用戶數很多的話,就用數據庫的方式進行管理
?
轉載于:https://www.cnblogs.com/St_Dlng/archive/2010/10/14/1851067.html
總結
以上是生活随笔為你收集整理的WinForm登录模块设计开发的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: UI分离引擎的设想
- 下一篇: 给opentaps添加定制的表和字段