C#下WinForm编程:登录窗体的设计

我在csdn里搜索了很久,也没有找到符合我要求的login文档,我这次把自己的心得和自己做的成果拿出来和大家分享一下,希望对后来的人能有一些帮助。我初次做,可能代码写的不是很规范,思路也不是很清晰,但是它能达到我要的效果就行了^_^      希望哪位兄弟帮忙完善一下我的代码。

我在数据库里有一个   users  的表,如下:

ID     UserName           UserPasswd

1        admin                    admin

2        user                        user

3        guest                     guest

我准备这样做,先判断输入的用户名是否和表里的UserName相同,如果相同,再比较相同UserName下的UserPasswd,如果这些都正确了,就可以进入系统了。

全部代码如下(我把我写的部分用黑体):

Form1的代码:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace login
{
 /// <summary>
 /// Form1 的摘要说明。
 /// </summary>
 public class Form1 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.Label label1;
  private System.Windows.Forms.Label label2;
  private System.Windows.Forms.TextBox txtUser;
  private System.Windows.Forms.TextBox txtPasswd;
  private System.Windows.Forms.Button btnOK;
  private System.Windows.Forms.Button btnCancel;

  /// <summary>
  /// 必需的设计器变量。
  /// </summary>
  private System.ComponentModel.Container components = null;

  public Form1()
  {
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent();

   
   //
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
  }

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows 窗体设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   thi

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值