我在bunifuTextbox
按键事件上使用此代码,它工作得很好:
//accept only 3 decimal places
if (System.Text.RegularExpressions.Regex.IsMatch(quantitytextbox.Text, @"\d+(\.\d{3,3})") && !char.IsControl(e.KeyChar))
{
e.Handled = true;
}
if (e.KeyChar == '.' && quantitytextbox.Text.Length == 0)
{
// Stop first char as a dot input
e.Handled = true;
}
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
{
e.Handled = true;
}
// only allow one decimal point
if ((e.KeyChar == '.') && ((sender as Bunifu.Framework.UI.BunifuMaterialTextbox).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
有人可以告诉我在'if'条件中加什么内容,因为这是我尝试为我的datagridview
使用此代码时发生的错误:
// only allow one decimal point
if ((e.KeyChar == '.') && ((sender as /* I dont know what to put here*/).Text.IndexOf('.') > -1))
{
e.Handled = true;
}