using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace 图书管理系统2
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }        private void button1_Click(object sender, EventArgs e)
        {
             string connstr = "Data Source=.;Initial Catalog=图书管理系统;Integrated Security=True"; 
              SqlConnection conn = new SqlConnection(connstr); 
              try 
              { 
              conn.Open(); 
              string select = "select * from 管理员登陆表 where 账号='" + 账号.Text + "'and 密码 = '" + 密码.Text + "'";
              SqlCommand cmd = new SqlCommand(select, conn);
              if (cmd.ExecuteScalar() != null)               {
                  this.Hide();
                  Form4 a = new Form4();
                  a.Show();
              }
              else
              {
                  MessageBox.Show("用户名或密码输入错误");
              }                 } 
              catch(Exception ex) 
              {
                  MessageBox.Show(ex.ToString());              }
                    
        }        }
    }
这是登陆的  要用鼠标点才行  想加段代码 按回车也可以~~!请高手帮忙!

解决方案 »

  1.   

    捕获keydown事件,如果是回车,执行相应事件
      

  2.   

    private void Form1_KeyPress(object sender, KeyPressEventArgs e)
            {//按下回车发送信息
                if (e.KeyChar == 13)
                {                    MessageBox.Show("aaaa");
                        return;        }
      

  3.   


    先问哈你啊
    账号.Text 与 密码.Text用的是TextBOX控件吗?
    如果是
    将下面的这段代码写在 密码.Text 的  KeyPress 事件下面就可以了
                  if (e.KeyChar == (char)Keys.Enter)
                 {
                    button1_Click(sender, e);
                 }
    不懂的话可以再问我的呵呵
      

  4.   

    呵呵,不是这样的啊:
    Form有个属性好象是是AcceptButton,你把这个属性选择成你的登陆按钮就可以了的。这样回车的时候就表示点了这个按钮