C# Winform文本框隐藏选择和GotFocus
有人能告诉我为什么以下两种代码有不同的行为吗?第一个代码将调用文本框C# Winform文本框隐藏选择和GotFocus,c#,winforms,textbox,C#,Winforms,Textbox,有人能告诉我为什么以下两种代码有不同的行为吗?第一个代码将调用文本框GotFocus事件,而第二个代码在执行lostfocus后不会调用GotFocus事件。请参考,HideSelection最初设置为false,以在第一时间高亮显示所有文本框 private void textBox_LostFocus(object sender, EventArgs e) { foreach (TextBox item in this.textbox) //got 3 text box,
GotFocus
事件,而第二个代码在执行lostfocus
后不会调用GotFocus
事件。请参考,HideSelection
最初设置为false,以在第一时间高亮显示所有文本框
private void textBox_LostFocus(object sender, EventArgs e)
{
foreach (TextBox item in this.textbox) //got 3 text box,
{
if (item.Focused == true)
{
item.HideSelection = false;
item.SelectAll();
}
else
item.HideSelection = true;
}
及
private void textBox_LostFocus(object sender, EventArgs e)
{
foreach (TextBox item in this.textbox) //got 3 text box,
{
if (item.Focused == true)
{
item.HideSelection = true; //difference here
item.HideSelection = false;
item.SelectAll();
}
else
item.HideSelection = true;
}