1,清空 控件的text 值
private void clearText( Control controlname)
{
for (int i = 0; i < controlname.Controls.Count; i++)
{
if (controlname.Controls[i].HasChildren)
{
clearText(controlname.Controls[i]);
}
else {
switch(controlname.Controls[i].GetType().Name){
case "TextBox":
controlname.Controls[i].Text = "";
continue;
case "RadioButton":
(controlname.Controls[i] as RadioButton).Checked = false;
continue;
case "CheckBox":
(controlname.Controls[i] as System.Windows.Forms.CheckBox).Checked = false;
continue;
case "ComboBox":
(controlname.Controls[i] as ComboBox).Text = "";
continue;
}
}
}
}
2,全角轉半角;
全角字符unicode编码从65281~65374 (十六进制 0xFF01 ~ 0xFF5E)
半角字符unicode编码从33~126 (十六进制 0x21~ 0x7E)
空格比较特殊,全角为 12288(0x3000),半角为 32 (0x20)
而且除空格外,全角/半角按unicode编码排序在顺序上是对应的
所以可以直接通过用+-法来处理非空格数据,对空格单独处理
/// <summary> 全角轉半角
///
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// /// 转半角的函数(DBC case) ///
/// 任意字符串
/// 半角字符串 ///
///全角空格为12288,半角空格为32
///其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248 ///
public static string ToDBC(string input)
{
if (input == null || input.Length == 0)
{
return String.empty;
}
char[] c = input.ToCharArray();
for (int i = 0; i < c.Length; i++)
{
if (c[i] == 12288)
{
c[i] = (char)32; continue;
}
if (c[i] > 65280 && c[i] < 65375)
c[i] = (char)(c[i] - 65248);
}
return new string(c);
}