C#的程序设计

来源:百度知道 编辑:UC知道 时间:2024/05/27 16:50:41
在窗体上放置两个标签控件。从键盘输入字符时,在两个标签上分别显示所键入的字符和该字符的ASCII值。按Enter键,清除标签上的内容。

namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != 13)
{
label1.Text = e.KeyChar.ToString();
int y = e.KeyChar;
label2.Text = y.ToString();
}
else
{
label1.Text = "";
label2.Text = "";
}
}

}
}