窗体中用小键盘输入

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace keypad { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button_Click(object sender, EventArgs e) { if (((Button)sender).Text == "大写") { KeyBoard1(); ((Button)sender).Text = ""; } if (((Button)sender).Text == "小写") { KeyBoard2(); ((Button)sender).Text = ""; } textBox1.Text += ((Button)sender).Text; } //大写+数字 private void KeyBoard1() { flowLayoutPanel1.Controls.Clear(); for (int i = 0; i < 10; i++) { Button button = new Button(); button.Width = 25; button.Height = 25; button.Text = ((char)(48 + i)).ToString(); flowLayoutPanel1.Controls.Add(button); button.Click += new EventHandler(button_Click); } for (int i = 0; i < 26; i++) { Button button = new Button(); button.Width = 25; button.Height = 25; button.Text = ((char)(65 + i)).ToString(); flowLayoutPanel1.Controls.Add(button); button.Click += new EventHandler(button_Click); } Button button1 = new Button(); button1.Width = 50; button1.Height = 25; button1.Text = "小写"; flowLayoutPanel1.Controls.Add(button1); button1.Click += new EventHandler(button_Click); } //小写+数字 private void KeyBoard2() { flowLayoutPanel1.Controls.Clear(); for (int i = 0; i < 10; i++) { Button button = new Button(); button.Width = 25; button.Height = 25; button.Text = ((char)(48 + i)).ToString(); flowLayoutPanel1.Controls.Add(button); button.Click += new EventHandler(button_Click); } for (int i = 0; i < 26; i++) { Button button = new Button(); button.Width = 25; button.Height = 25; button.Text = ((char)(97 + i)).ToString(); flowLayoutPanel1.Controls.Add(button); button.Click += new EventHandler(button_Click); } Button button1 = new Button(); button1.Width = 50; button1.Height = 25; button1.Text = "大写"; flowLayoutPanel1.Controls.Add(button1); button1.Click += new EventHandler(button_Click); } private void button1_Click(object sender, EventArgs e) { if (flowLayoutPanel1.Visible) { flowLayoutPanel1.Visible = false; } else { flowLayoutPanel1.Visible = true; KeyBoard2(); } } } }

你可能感兴趣的:(窗体中用小键盘输入)