CreateIconIndirect()的API函数可以生成Icon图像
Icon和Cursor实际是同一个结构,fIcon字段区别是否为Icon
字段hbmMask和hbmColor指定掩码图和色彩图
当然,更好的是用Bitmap.MakeTransparent()处理一下透明
这样掩码图和色彩图都指向处理后的位图
public double DecodeMoneyCn( string AText)
{
AText = AText.Replace("亿亿", "兆");
AText = AText.Replace("万万", "亿");
AText = AText.Replace("点", "元");
AText = AText.Replace("块", "元");
AText = AText.Replace("毛", "角");
double vResult = 0;
double vNumber = 0; // 当前数字
double vTemp = 0;
int vDecimal = 0; // 是否出现小数点
foreach (char vChar in AText)
{
int i = "零一二三四五六七八九".IndexOf(vChar);
if (i < 0) i = "洞幺两三四五六拐八勾".IndexOf(vChar);
if (i < 0) i = "零壹贰叁肆伍陆柒捌玖".IndexOf(vChar);
if (i > 0)
{
vNumber = i;
if (vDecimal > 0)
{
vResult += vNumber * Math.Pow(10, -vDecimal);
vDecimal++;
vNumber = 0;
}
}
else
{
i = "元十百千万亿".IndexOf(vChar);
if (i < 0) i = "整拾佰仟万亿兆".IndexOf(vChar);
if (i == 5) i = 8;
if (i == 6) i = 12;
if (i > 0)
{
if (i >= 4)
{
vTemp += vNumber;
if (vTemp == 0) vTemp = 1;
vResult += vTemp * Math.Pow(10, i);
vTemp = 0;
}
else vTemp += vNumber * Math.Pow(10, i);
}
else
{
i = "元角分".IndexOf(vChar);
if (i > 0)
{
vTemp += vNumber;
vResult += vTemp * Math.Pow(10, -i);
vTemp = 0;
}
else if (i == 0)
{
vTemp += vNumber;
vResult += vTemp;
vDecimal = 1;
vTemp = 0;
}
}
vNumber = 0;
}
}
return vResult + vTemp + vNumber;
}
private void button1_Click( object sender, EventArgs e)
{
string[] vTestText = {
"十二点五六",
"一亿零一万零五",
"四万万",
"九十八亿七千六百五十四万三千二百一十",
"五元一角四分", "壹佰元整",
"三千五百万",
"九块二毛"};
foreach (string vText in vTestText)
{
Console.WriteLine("DecodeMoneyCn("{0}")={1}", vText,
DecodeMoneyCn(vText));
}
//输出
//DecodeMoneyCn("十二点五六")=2.56
//DecodeMoneyCn("一亿零一万零五")=100010005
//DecodeMoneyCn("四万万")=400000000
//DecodeMoneyCn("九十八亿七千六百五十四万三千二百一十")=9876543210
//DecodeMoneyCn("五元一角四分")=5.14
//DecodeMoneyCn("壹佰元整")=100
//DecodeMoneyCn("三千五百万")=35000000
//DecodeMoneyCn("九块二毛")=9.2
//DecodeMoneyCn("一兆")=1000000000000
}
{
AText = AText.Replace("亿亿", "兆");
AText = AText.Replace("万万", "亿");
AText = AText.Replace("点", "元");
AText = AText.Replace("块", "元");
AText = AText.Replace("毛", "角");
double vResult = 0;
double vNumber = 0; // 当前数字
double vTemp = 0;
int vDecimal = 0; // 是否出现小数点
foreach (char vChar in AText)
{
int i = "零一二三四五六七八九".IndexOf(vChar);
if (i < 0) i = "洞幺两三四五六拐八勾".IndexOf(vChar);
if (i < 0) i = "零壹贰叁肆伍陆柒捌玖".IndexOf(vChar);
if (i > 0)
{
vNumber = i;
if (vDecimal > 0)
{
vResult += vNumber * Math.Pow(10, -vDecimal);
vDecimal++;
vNumber = 0;
}
}
else
{
i = "元十百千万亿".IndexOf(vChar);
if (i < 0) i = "整拾佰仟万亿兆".IndexOf(vChar);
if (i == 5) i = 8;
if (i == 6) i = 12;
if (i > 0)
{
if (i >= 4)
{
vTemp += vNumber;
if (vTemp == 0) vTemp = 1;
vResult += vTemp * Math.Pow(10, i);
vTemp = 0;
}
else vTemp += vNumber * Math.Pow(10, i);
}
else
{
i = "元角分".IndexOf(vChar);
if (i > 0)
{
vTemp += vNumber;
vResult += vTemp * Math.Pow(10, -i);
vTemp = 0;
}
else if (i == 0)
{
vTemp += vNumber;
vResult += vTemp;
vDecimal = 1;
vTemp = 0;
}
}
vNumber = 0;
}
}
return vResult + vTemp + vNumber;
}
private void button1_Click( object sender, EventArgs e)
{
string[] vTestText = {
"十二点五六",
"一亿零一万零五",
"四万万",
"九十八亿七千六百五十四万三千二百一十",
"五元一角四分", "壹佰元整",
"三千五百万",
"九块二毛"};
foreach (string vText in vTestText)
{
Console.WriteLine("DecodeMoneyCn("{0}")={1}", vText,
DecodeMoneyCn(vText));
}
//输出
//DecodeMoneyCn("十二点五六")=2.56
//DecodeMoneyCn("一亿零一万零五")=100010005
//DecodeMoneyCn("四万万")=400000000
//DecodeMoneyCn("九十八亿七千六百五十四万三千二百一十")=9876543210
//DecodeMoneyCn("五元一角四分")=5.14
//DecodeMoneyCn("壹佰元整")=100
//DecodeMoneyCn("三千五百万")=35000000
//DecodeMoneyCn("九块二毛")=9.2
//DecodeMoneyCn("一兆")=1000000000000
}