[ prog / sol / mona ]

sol


What's on your mind?

9 2023-04-16 10:37

private bool IsValidInteger (out int result, TextBox txt, string name, int min = int.MinValue, int max = int.MaxValue)

{

// Get the text.

string text = txt. Text;

// If there is something wrong, build an error message.

string message = "";

if (text.Length == 0) message = "Please enter " + name + " . ";

else if (!int.TryParse (text, out result))

message = "Error parsing " + name + " '" + text + "'";

else if ((result < min) || (result > max))

message = name + " must be between " + min.ToString() + " and " + max.ToString() + ".";

// See if we have an error message.

if (message.Length > 0)

{

// Display the message, select the Textbox's text.

// give it focus, and return false.

MessageBox. Show (message, name + "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

txt.Select (0, text.Length);

txt. Focus();

return false;

}

// The value is okay.

return true;

}

39


VIP:

do not edit these