using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _036字母与ASCII码转换
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_AscII_Click(object sender, EventArgs e)
{
if(txt_Char1.Text!= string.Empty)
{
if(Encoding.GetEncoding("Unicode").GetBytes(new char[] {txt_Char1.Text[0]})[1]==0)
{
txt_Ascii1.Text = Encoding.GetEncoding("Unicode").GetBytes(txt_Char1.Text)[0].ToString();
// txt_Ascii1.Text = Convert.ToString(System.Text.Encoding.ASCII.GetBytes(txt_Char1.Text)[0]);
}
else
{
txt_Ascii1.Text = string.Empty;
MessageBox.Show("请输入字母!","提示!");
}
}
}
private void btn_Char_Click(object sender, EventArgs e)
{
if(txt_Ascii2.Text!= string.Empty)
{
int P_int_Num;
if (int.TryParse(
txt_Ascii2.Text,out P_int_Num))
{
txt_Char2.Text =
((char)P_int_Num).ToString();
}
else
{
MessageBox.Show(
"请输入正确的ASCII码","错误!");
}
}
}
}
}