C#控制TextBox输入的源代码: public static void KeyPressUFloat( object sender, KeyPressEventArgs e, int decCount) ... { TextBox txtBox = (TextBox)sender; int curPos = txtBox.SelectionStart; // 当前光标位置 int pointPos = txtBox.Text.LastIndexOf('.'); // 小数点位置 // 输入位置在两位小数点后,不允许输入 if ((pointPos > 0) && (curPos > (pointPos + decCount))) ...{ if (e.KeyChar != '') ...{ e.Handled = true; } return; } try ...{ string strInt = txtBox.Text.Trim().Substring(0, curPos); string strDec = "";