更新时间:2023-10-29 15:36:52
假设我理解正确,这里是我对问题解释的回答
Assuming I understand the question correctly, here's my answer to the interpretation of the question
private void Form1_Load(object sender, EventArgs e)
{
foreach (TextBox tb in this.Controls.OfType<TextBox>())
{
tb.Enter += new EventHandler(textBoxAll_Enter);
tb.Leave += new EventHandler(textBoxAll_Leave);
}
}
private void textBoxAll_Enter(object sender, EventArgs e)
{
((TextBox)sender).Text = "textbox gained focus";
}
private void textBoxAll_Leave(object sender, EventArgs e)
{
((TextBox)sender).Text = "textbox lost focus";
}