Tôi thêm một handler để textbox sử dụng đoạn mã sau:Add/Remove xử lý để textbox
private void frmLogin_Load(object sender, EventArgs e)
{
foreach (Control tb in this.Controls)
{
if (tb is TextBox)
{
TextBox tb1 = (TextBox)tb;
tb1.KeyDown += new KeyEventHandler(TextBox_KeyDown);
}
}
}
Tôi cũng loại bỏ handler sử dụng đoạn mã sau:
private void frmLogin_FormClosed(object sender, FormClosedEventArgs e)
{
foreach (Control tb in this.Controls)
{
if (tb is TextBox)
{
TextBox tb1 = (TextBox)tb;
tb1.KeyDown -= new KeyEventHandler(TextBox_KeyDown);
}
}
}
có phải là cách đúng hay Có một lựa chọn tốt hơn?
Và tôi biết trình biên dịch tạo trình xử lý thêm bằng KeyEventHandler mới, nhưng công cụ tái cấu trúc của tôi cho tôi biết đây là Tạo ủy quyền dự phòng. – Piyey