C# Winform程序经验之实现简单的Login窗口.doc
6页1、最近,看到网上经常会问如何进行窗口跳转,大多数的问题都是牵扯到Login窗口。其实,在Visual Studio 6以来,比较正确的做法,是判断Login窗口的返回值,然后决定是否打开主窗体,那么在C#中也是一样的。具体做法如下:首先,创建Login窗口,然后添加相应的输入框和按钮,设置窗口的AcceptButton为窗体的确认按钮,而CancelButton为窗体 的取消按钮。例如: this.AcceptButton = this.btnOK; this.CancelButton = this.btnCancel;定义确定按钮以及取消按钮事件,如下: private void btnOK_Click(object sender, System.EventArgs e) / Here is to use fixed username and password / You can check username and password from DB if( txtUserName.Text = Admin & txtPassword.Text = nopassword ) / Sav
2、e login user info uiLogin.UserName = txtUserName.Text; uiLogin.Password = txtPassword.Text; / Set dialog result with OK this.DialogResult = DialogResult.OK; else / Wrong username or password nLoginCount+; if( nLoginCount = MAX_LOGIN_COUNT ) / Over 3 times this.DialogResult = DialogResult.Cancel; else MessageBox.Show( Invalid user name and password! ); txtUserName.Focus(); private void btnCancel_Click(object sender, System.EventArgs e) / Set dialog result with Cancel this.DialogResult = DialogRes
3、ult.Cancel; 然后,在Login窗体的Closing事件中,要进行处理,如下:private void frmLogin_Closing(object sender, System.ComponentModel.CancelEventArgs e) / Check whether form is closed with dialog result if( this.DialogResult != DialogResult.Cancel & this.DialogResult != DialogResult.OK ) e.Cancel = true;除此外,Login窗体一些辅助代码如下: private int nLoginCount = 0; private const int MAX_LOGIN_COUNT = 3; private UserInfo uiLogin; public frmLogin( ref UserInfo ui ) / / Required for Windows Form Designer support / InitializeComponent(); / Set login info to class member uiLogin = ui; 调用的时候,要修改程序的Main函数,如下: / / The main entry point for the application. / STAThread static void Main() UserInfo ui = new UserInfo(); frmLogin myLogin = new frmLogin( ref ui ); if( myLogin.ShowDialog() = DialogResult.OK ) /Open your main form here MessageBox.Show( Logged in successfully! );
《C# Winform程序经验之实现简单的Login窗口.doc》由会员小**分享,可在线阅读,更多相关《C# Winform程序经验之实现简单的Login窗口.doc》请在金锄头文库上搜索。
2020年高考真题——理科综合(全国卷Ⅲ)+Word版含答案
2021年绝味鸭脖策划书
2021年熟食店创业方案
2021年熟食店开店策划
2021年卤菜店创业计划书
2021年周黑鸭网络营销策划方案
东大21年1月考试《现代设计方法》考核作业
谈我国行政管理效率的现状及其改观对策(论文)
单证员考试-备考辅导-复习资料:无贸易背景信用证案分析.docx
土木工程毕业生答辩自述.docx
建筑学毕业后工作状态真实写照.doc
C#代码规范(湖南大学).doc
xx区食药监局2019年工作总结及2020年工作计划
2019年中医院药物维持治疗门诊工人先锋号先进事迹
2019年度xx乡镇林长制工作总结
2019年性艾科工作计划书
2019年人才服务局全国扶贫日活动开展情况总结
关于组工信息选题的几点思考
摘了穷帽子 有了新模样
2019年某集团公司基层党支部书记培训班心得体会
2024-04-08 33页
2024-04-08 10页
2024-04-08 25页
2024-04-08 12页
2024-04-08 10页
2024-04-08 21页
2024-04-08 40页
2024-04-08 34页
2024-04-08 28页
2024-04-08 28页