validation.cs

来自「c#标准教程适合与处于不同学习阶段的人」· CS 代码 · 共 38 行

CS
38
字号
using System;
using SWF = System.Windows.Forms;

namespace BankCustomerApp
{

	public class Validation
	{

		public static void IsInteger(object sender, System.ComponentModel.CancelEventArgs e)
		{
			SWF.TextBox  txt;
			txt = (SWF.TextBox) sender;

			try
			{
				int.Parse(txt.Text);
			}
			catch(FormatException)
			{
				SWF.MessageBox.Show("Please enter a numeric value.", "Bank Customer App");
				e.Cancel = true;  // cancel validation, returns focus
			}
			catch(OverflowException)
			{
				SWF.MessageBox.Show("Please enter an integer in the range " + int.MinValue + " ... " + int.MaxValue, "Bank Customer App");
				e.Cancel = true;  // cancel validation, returns focus
			}
			catch(Exception ex)
			{
				SWF.MessageBox.Show("Unknown error: " + ex.Message, "Bank Customer App");
				e.Cancel = true;  // cancel validation, returns focus
			}
		}
	
	}//class
}//namespace

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?