日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

WinForm登录模块设计开发

發布時間:2024/4/14 编程问答 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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登录模块设计开发的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。