Using Validating and Validated events gives you way to catch error when textbox loses focus.
This little example will not let user move to another control until they have entered a valid input. Normally would add check if empty or whitespace so they could clear it and move on.
Uses a errorprovider and changes backcolor to notify user.
Pics below for error and good.
code
public partial class Form1 : Form
{
private Color TextBackColor { get; set; }
public Form1()
{
InitializeComponent();
TextBackColor = textBox1.BackColor;
}
private void button1_Click(object sender, EventArgs e)
{
}
private void textBox1_Validating(object sender, CancelEventArgs e)
{
try
{
textBox2.Text = Converter.StringToDistance(textBox1.Text).ToString(CultureInfo.InvariantCulture);
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
e.Cancel = true;
if (ex.ErrorStatus == ErrorStatus.InvalidInput)
{
errorProvider1.SetError(textBox1, "Invalid");
textBox1.BackColor = Color.LightCoral;
}
else
{
throw;
}
}
}
private void textBox1_Validated(object sender, EventArgs e)
{
errorProvider1.SetError(textBox1, "");
textBox1.BackColor = TextBackColor;
}
}
Attached project used Autodesk's plugin and referenced 2013 assemblies
Here is a link for more info
http://msdn.microsoft.com/en-us/library/vstudio/system.windows.forms.control.validating(v=vs.100).aspx