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 ASCII
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
}
private void Frm_Main_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
private void bth_ToASCII_Click(object sender,EventArgs e)
{
if (txt_char.Text != string.Empty)
{
if (Encoding.GetEncoding("unicode").
GetBytes(new char[] { txt_char.Text[0] })[1] == 0)
{
txt_ASCII.Text = Encoding.GetEncoding(
"unicode").GetBytes(txt_char.Text).ToString();
}
else
{
txt_ASCII.Text = string.Empty;
MessageBox.Show("请输入字母!", "提示");
}
}
}
private void bth_ToChar_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码值。", "错误");
}
}
}
}
}