惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - LiShijin.Net

即刻完成你的ASP.NET程序 ASP.NET 2.0,无刷新页面新境界! ASP.NET四种页面导航方式之比较与选择 十天学会ASP.net之第十天 - LiShijin.Net - 博客园 十天学会ASP.net之第九天 - LiShijin.Net - 博客园 十天学会ASP.net之第八天 - LiShijin.Net - 博客园 十天学会ASP.net之第七天 十天学会ASP.net之第六天 十天学会ASP.net之第五天 - LiShijin.Net - 博客园 用ASP.NET加密Cookie数据 Bill Gates 的大学毕业典礼演讲 asp.net图书请教 .NET程序设计之四书五经 驻留多个 Web 应用程序 确保 ASP.NET 应用程序和 Web Services 的安全 检查表:保护 ASP.NET 的安全 构建安全的 ASP.NET 网页和控件 如何利用窗体身份验证创建 GenericPrincipal 对象 在asp.net中为Web用户控件添加属性和事件
WindowsForm登陆窗体的建立
LiShijin.Net · 2004-08-10 · via 博客园 - LiShijin.Net

常常有人问道如何创建登陆的问题,很多人觉得应该使用多线程。事实上,根本不需要用到多线程。下面,我就将整个过程详细的写出来,以帮助初学者。

  假设您现在已经有了一个WondowsForm应用的工程,并且已经有了主窗体,名为Form1(即程序入口点所在的窗体)

  1、 新添加一个窗体,这个窗体将作为你的登陆窗体。

  我的示例窗体是这样的,textbox中的文字是它的名字。

  2、 接下来在Form2,也就是这个登陆窗体的代码视图中加入

  private bool ISLOGIN = false;

 就加在其构造函数的前面。这东西我们等下要用。

  然后加一个属性

  public bool isLogin
 
  {

  get

  {

  return this.ISLOGIN;

  }
 
  }

  3、 在Login按钮的Click事件处理方法中加入你自己的验证代码,可以是读数据库,也可以是别的任何的方法。这里,我就举个最简单的例子

  if(this.txtUserID.Text =="Reeezak" && this.txtPassword.Text == "CSDN")

  {

   this.ISLOGIN = true;

  this.Close();//登陆成功才关闭登陆登陆窗体

  }

  else

  {

  MessageBox.Show("Invalid User or Password,try again!");

  }
 
  4、 在主窗体中main方法里面,将代码改成

  Form2 f2 = new Form2();

  f2.ShowDialog();

  if(f2.isLogin == true)

  {

  Application.Run(new Form1());

  }

  5、 最后,说一说那两个按钮的问题。不能将Login按钮的DialogResult设置成“OK”(最好就设置成None,反正我们自定义了)否则,不论登陆成功与否都会关闭登陆窗体。我们在它的Click事件处理方法里面已经有了this.Close()所以就不需要了。

  关于Cancel按钮,有两个办法。最方便的就是将其DialogResult设置为cancel。如果设置为none,则给它添加一个Click事件处理方法,里面的内容就一句,this.Close();

  就这样几句代码,登陆窗体就搞掂了,很简单吧?^_^