首页 > 代码库 > combobox和textbox中输入数据为非数字leave时的公用事件,只需要在控件的leave事件中选择本事件即可

combobox和textbox中输入数据为非数字leave时的公用事件,只需要在控件的leave事件中选择本事件即可

private void tbORcbb_leave(object sender, EventArgs e)
        {
            if (typeof(TextBox).IsInstanceOfType(sender))
            {
                if (((TextBox)sender).Text.IsNumeric() != true)
                {
                    ((TextBox)sender).Focus();
                    ((TextBox)sender).SelectAll();
                }
            }
            else if  (typeof(ComboBox).IsInstanceOfType(sender))
            {
                if (((ComboBox)sender).Text.IsNumeric() != true)
                {
                    ((ComboBox)sender).Focus();
                    ((ComboBox)sender).SelectAll();
                }
            }
        }