using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (!IsNum(textBox1.Text.Trim()))
{
MessageBox.Show("你输入的不是数字,请重新输入!!");
textBox1.Focus();
return;
}
textBox2.Text = ChangeToNew(textBox1.Text);
}
public bool IsNum(string str)//判断输入的字符是不是数字
{
return System.Text.RegularExpressions.Regex.IsMatch(str, @"^[0-9]*$");
}
public string ChangeToChar(string str)
{
string ch = "零";
switch (str)
{
case "0": ch = "零";
break;
case "1": ch = "壹";
break;
case "2": ch = "贰";
break;
case "3": ch = "叁";
break;
case "4": ch = "肆";
break;
case "5": ch = "伍";
break;
case "6": ch = "陆";
break;
case "7": ch = "柒";
break;
case "8": ch = "捌";
break;
case "9": ch = "玖";
break;
}
return ch;
}
public int NumBase(int length)
{
int j = 10;
for (int i = 0; i <length; i++)
{
if (i == 0)
{
j = 1;
}
else if (i == 1)
{
j = 10;
}
else
{
j = j * 10;
}
}
return j;
}
public string ChangeToNew(string str)
{
int NumLength = str.Length;
StringBuilder sb = new StringBuilder();
int numStr = 0;
try
{
numStr = int.Parse(str.Trim());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
int numTemp = 0;
for (int i = NumLength ; i>0; i--)
{
int j = numStr / NumBase(i);
numTemp = numStr;
numStr = numTemp - j * NumBase(i);
string g = ChangeToChar(j.ToString ());
switch (i)
{
case 0: sb.Append(g); break;
case 1: sb.Append(g + "元整"); break;
case 2: sb.Append(g+"十"); break;
case 3: sb.Append(g+"百"); break;
case 4: sb.Append(g + "千"); break;
case 5: sb.Append(g + "万"); break;
case 6: sb.Append(g + "十"); break;
case 7: sb.Append(g + "百"); break;
case 8: sb.Append(g + "千"); break;
case 9: sb.Append(g + "亿"); break;
case 10: sb.Append(g + "十"); break;
case 11: sb.Append(g + "百"); break;
case 12: sb.Append(g + "千"); break;
case 13: sb.Append(g + "兆"); break;
}
}
return sb.ToString();
}
}
}