本文整理汇总了C#中System.Windows.Forms.Control.LostFocus事件的典型用法代码示例。如果您正苦于以下问题:C# Control.LostFocus事件的具体用法?C# Control.LostFocus怎么用?C# Control.LostFocus使用的例子?那么恭喜您, 这里精选的事件代码示例或许可以为您提供帮助。
在下文中一共展示了Control.LostFocus事件的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: textBox1_Validating
private void textBox1_Validating(object sender,
System.ComponentModel.CancelEventArgs e)
{
// If nothing is entered,
// an ArgumentException is caught; if an invalid directory is entered,
// a DirectoryNotFoundException is caught. An appropriate error message
// is displayed in either case.
try
{
System.IO.DirectoryInfo directory =
new System.IO.DirectoryInfo(textBox1.Text);
directory.GetFiles();
errorProvider1.SetError(textBox1, "");
}
catch(System.ArgumentException ex1)
{
errorProvider1.SetError(textBox1, "Please enter a directory");
}
catch(System.IO.DirectoryNotFoundException ex2)
{
errorProvider1.SetError(textBox1, "The directory does not exist." +
"Try again with a different directory.");
}
}
// This method handles the LostFocus event for textBox1 by setting the
// dialog's InitialDirectory property to the text in textBox1.
private void textBox1_LostFocus(object sender, System.EventArgs e)
{
openFileDialog1.InitialDirectory = textBox1.Text;
}
// This method demonstrates using the ErrorProvider.GetError method
// to check for an error before opening the dialog box.
private void button1_Click(System.Object sender, System.EventArgs e)
{
//If there is no error, then open the dialog box.
if (errorProvider1.GetError(textBox1)=="")
{
DialogResult dialogResult = openFileDialog1.ShowDialog();
}
}