如何重写以下代码,而不是重写15次,我只能使用一个子代码:
Private Sub txtQuestionValue01_Leave(sender As Object, e As EventArgs) Handles txtQuestionValue01.Leave
txtQuestionValue01.Text = txtQuestionValue01.Text.TrimStart("0"c)
End Sub
目标是,因为每个文本框都分配了1到20的数字,所以我想重写它以便它查找txtQuestionValue02.Leave
并继续txtQuestionValue20.Leave
答案 0 :(得分:1)
你可以像这样组合它们:
Private Sub TextBoxes_Leave(sender As Object, e As EventArgs) Handles txtQuestionValue01.Leave, txtQuestionValue02.Leave
DirectCast(sender, TextBox).Text = DirectCast(sender, TextBox).Text.TrimStart("0"c)
End Sub
答案 1 :(得分:0)
您可以对所有事件使用相同的事件处理程序:
Handles txtQuestionValue01.Leave, txtQuestion02.Leave, txtQuestionValue03.Leave....