某触摸屏程序登录界面设计

程序界面布局如下图

 

1.新建一个Windows应用程序。

2.界面布局如上图。

3.设置窗体的StartPosition属性值为CenterScreen,WindowState属性为Maximized,ControlBox属性为false,BackgroundImageLayout属性为 Stretch,自己在本地计算机选择一张背景图片。

4.进入代码界面添加一个命名空间引用

using System.Runtime.InteropServices;

5.各按钮功能代码实现

  public partial class login : Form { public login() { InitializeComponent(); } public bool a = true; bool b = false; bool c = false; //文本框锁定 public void textselect() { if (b == true) { this.txtPwd.Focus(); } else if (b == false) { this.txtName.Focus(); } } private void BtnExit_Click(object sender, EventArgs e) { Application.Exit(); } private void panel1_Paint(object sender, PaintEventArgs e) { //this.panel1.BringToFront(); panel1.Location = new Point(this.Width / 2 - panel1.Width / 2, this.Height / 2 - panel1.Height / 2); } private void Form1_Load(object sender, EventArgs e) { this.txtName.Focus(); this.txtName.BringToFront(); panel2.Hide(); timer.Enabled = true; } private void Btn1_Click(object sender, EventArgs e) { textselect(); for (int i = 1; i < 2; i++) { SendKeys.Send(i.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void Btn2_Click(object sender, EventArgs e) { textselect(); for (int i = 2; i < 3; i++) { SendKeys.Send(i.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void Btn3_Click(object sender, EventArgs e) { textselect(); for (int i = 3; i < 4; i++) { SendKeys.Send(i.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void Btn4_Click(object sender, EventArgs e) { textselect(); for (int i = 4; i < 5; i++) { SendKeys.Send(i.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void Btn5_Click(object sender, EventArgs e) { textselect(); for (int i = 5; i < 6; i++) { SendKeys.Send(i.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void Btn6_Click(object sender, EventArgs e) { textselect(); for (int i = 6; i < 7; i++) { SendKeys.Send(i.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void Btn7_Click(object sender, EventArgs e) { textselect(); for (int i = 7; i < 8; i++) { SendKeys.Send(i.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void Btn8_Click(object sender, EventArgs e) { textselect(); for (int i = 8; i < 9; i++) { SendKeys.Send(i.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void Btn9_Click(object sender, EventArgs e) { textselect(); for (int i = 9; i < 10; i++) { SendKeys.Send(i.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void Btn0_Click(object sender, EventArgs e) { textselect(); for (int i = 0; i < 1; i++) { SendKeys.Send(i.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnBackspace_Click(object sender, EventArgs e) { textselect(); SendKeys.Send("{Backspace}"); } //软键盘 private void panel2_Paint(object sender, PaintEventArgs e) { this.panel2.BringToFront(); panel2.Location = new Point(this.Width / 2 - panel2.Width / 2, this.Height / 2 + panel1.Height / 2); } private void BtnSoftKeyboard_Click(object sender, EventArgs e) { if (c == true) { textselect(); panel2.Hide(); c = false; } else { textselect(); panel2.Show(); c = true; } } private void panel1_Click(object sender, EventArgs e) { panel2.Hide(); c = false; } private void login_Click(object sender, EventArgs e) { panel2.Hide(); c = false; } private void BtnA_Click(object sender, EventArgs e) { textselect(); for (int i = 97; i < 98; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } //调用系统的USER32.DLL共享文件 [DllImport("user32.dll",CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo); //退格键 private void BtnCapsLock_Click(object sender, EventArgs e) { const int KEYEVENTF_EXTENDEDKEY = 0x1; const int KEYEVENTF_KEYUP = 0x2; keybd_event(0x14, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0); keybd_event(0x14, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, (UIntPtr)0); } private void BtnB_Click(object sender, EventArgs e) { textselect(); for (int i = 98; i < 99; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnC_Click(object sender, EventArgs e) { textselect(); for (int i = 99; i < 100; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnD_Click(object sender, EventArgs e) { textselect(); for (int i = 100; i < 101; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnE_Click(object sender, EventArgs e) { textselect(); for (int i = 101; i < 102; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnF_Click(object sender, EventArgs e) { textselect(); for (int i = 102; i < 103; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnG_Click(object sender, EventArgs e) { textselect(); for (int i = 103; i < 104; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnH_Click(object sender, EventArgs e) { textselect(); for (int i = 104; i < 105; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnI_Click(object sender, EventArgs e) { textselect(); for (int i = 105; i < 106; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnJ_Click(object sender, EventArgs e) { textselect(); for (int i = 106; i < 107; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnK_Click(object sender, EventArgs e) { textselect(); for (int i = 107; i < 108; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnL_Click(object sender, EventArgs e) { textselect(); for (int i = 108; i < 109; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnM_Click(object sender, EventArgs e) { textselect(); for (int i = 109; i < 110; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnN_Click(object sender, EventArgs e) { textselect(); for (int i = 110; i < 111; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnO_Click(object sender, EventArgs e) { textselect(); for (int i = 111; i < 112; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnP_Click(object sender, EventArgs e) { textselect(); for (int i = 112; i < 113; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnQ_Click(object sender, EventArgs e) { textselect(); for (int i = 113; i < 114; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnR_Click(object sender, EventArgs e) { textselect(); for (int i = 114; i < 115; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnS_Click(object sender, EventArgs e) { textselect(); for (int i = 115; i < 116; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnT_Click(object sender, EventArgs e) { textselect(); for (int i = 116; i < 117; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnU_Click(object sender, EventArgs e) { textselect(); for (int i = 117; i < 118; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnV_Click(object sender, EventArgs e) { textselect(); for (int i = 118; i < 119; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnW_Click(object sender, EventArgs e) { textselect(); for (int i = 119; i < 120; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnX_Click(object sender, EventArgs e) { textselect(); for (int i = 120; i < 121; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnY_Click(object sender, EventArgs e) { textselect(); for (int i = 121; i < 122; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnZ_Click(object sender, EventArgs e) { textselect(); for (int i = 122; i < 123; i++) { char Letter = (char)i; SendKeys.Send(Letter.ToString()); System.Threading.Thread.Sleep(100); SendKeys.Flush(); } } private void BtnDel_Click(object sender, EventArgs e) { textselect(); SendKeys.Send("{Delete}"); } private void txtName_Click(object sender, EventArgs e) { b = false; } private void txtPwd_Click(object sender, EventArgs e) { b = true; } private void timer_Tick(object sender, EventArgs e) { if (a == true) { panel1.Show(); } else if (a == false) { panel1.Hide(); panel2.Hide(); } } //修改密码 private void BtnModifyPwd_Click(object sender, EventArgs e) { ModifyPwd mp = new ModifyPwd(); mp.Show(); a = false; } //登录按钮 private void btLogin_Click(object sender, EventArgs e) { if (txtName.Text == "abc" && txtPwd.Text == "123") { Client c = new Client(); c.Show(); this.Hide(); } else { MessageBox.Show("用户名或密码错误,请重新输入", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }

 

6.代码中涉及到ModifyPwd(修改密码窗口)和Client(用户客户端程序窗口)自行添加就是了没有功能实现

 

你可能感兴趣的:(C#)