今天在完成登录系统时,主要遇到了两个问题,
一是让窗体获得按键,刚开始做的时候,窗体没有办法获得按键输入,原来是要设置this.KeyPreview = true;属性,窗体才能够获得按键输入;
二是窗体的FormBorderStyle属性值的意义:
Fixed3D 固定的三维边框。
FixedDialog 固定的对话框样式的粗边框。
FixedSingle 固定的单行边框。
FixedToolWindow 不可调整大小的工具窗口边框。工具窗口不会显示在任务栏中也不会显示在当用户按 Alt+Tab 时出现的窗口中。尽管指定 FixedToolWindow 的窗体通常不显示在任务栏中,还是必须确保 ShowInTaskbar 属性设置为 false,因为其默认值为 true
None 无边框
Sizable 可调整大小边框
SizeableToolWindow 可调整大小的工具窗口边框。工具窗口不会显示在任务栏中也不会显示在当用户按 Alt+Tab 时出现的窗口中。
但对网上说的当把FormBorderStyle=None,在Win7窗体中不会有一些动态效果,还不是很理解。要加强学习
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Configuration;
5 using System.Data;
6 using System.Data.SqlClient;
7 using System.Drawing;
8 using System.Linq;
9 using System.Text;
10 using System.Threading.Tasks;
11 using System.Windows.Forms;
12
13 namespace _01登录练习
14 {
15 public partial class frmLogin : Form
16 {
17 public frmLogin()
18 {
19 InitializeComponent();
20 }
21
22 private void btnXCancel_Click(object sender, EventArgs e)
23 {
24 DialogResult dr= MessageBox.Show("确定要退出吗?", "退出", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
25
26 if(dr==DialogResult.Yes )
27 {
28 Application.Exit();
29 }
30
31 }
32
33 private void btnXLogin_Click(object sender, EventArgs e)
34 {
35 CheckUid();
36
37 }
38
39 private void CheckUid()
40 {
41 string uid = txtXUid.Text.Trim();
42 string pwd = txtXPwd.Text;
43 if (uid.Length > 0 && pwd.Length > 0)
44 {
45 string sql = "select count(*) from kdUser where uName=@uid and uPassword=@pwd";
46 SqlParameter[] ps =
47 {
48 new SqlParameter ("@uid",uid),
49 new SqlParameter ("@pwd",pwd)
50 };
51 int result = (int)SqlHelper.ExecuteScalar(sql, CommandType.Text, ps);
52 if (result > 0)
53 {
54 MessageBox.Show("登录成功", "消息");
55 }
56 else
57 {
58 MessageBox.Show("登录失败", "消息");
59 txtXPwd.Clear();
60 txtXUid.Clear();
61 }
62
63 }
64 else
65 {
66 MessageBox.Show("请输入用户名或者密码");
67 txtXUid.Focus();
68 }
69 }
70
71
72 private void frmLogin_KeyDown(object sender, KeyEventArgs e)
73 {
74
75 }
76
77 private void btnXLogin1(object sender, KeyEventArgs e)
78 {
79 if(e.KeyData ==Keys.F5 )
80 {
81 CheckUid();
82 }
83 }
84 }
85 }
来源:https://www.cnblogs.com/yolin/p/5218781.html