0

vb.netでは、検証中に、検証を呼び出すコントロールの名前をどのように決定しますか? ActiveControl コマンドは、検証中のコントロールではなく、フォーカスを取得する NEXT コントロールの名前を返します。

4

2 に答える 2

0

J に感謝します...間違っていたら訂正してください。しかし、「送信者」オブジェクトをコントロールとして参照できるようにする秘訣は、変数を System.Object から Control オブジェクトに変換することのようです。 3行目で達成。Dim ctl As Control = 送信者

Private Sub PhoneValidation(sender As System.Object, e As System.ComponentModel.CancelEventArgs)     Handles PhoneHomeTextBox.Validating, PhoneMobileTextBox.Validating, PhoneWorkTextBox.Validating

    'This routine strips away all non-numeric characters, and then reformats the remaining 10 digits in standard phone# format.  It rejects any non-null input which does not distill down to exactly 10 or 11 digits

    Dim ctl As Control = sender

    If ctl.Text = "" Then Exit Sub

    Dim x As String = ""
    Dim y As String = ""
    Dim z As String = "0123456789"

    For i = 0 To Len(ctl.Text) - 1
        x = ctl.Text.Substring(i, 1)
        If z.IndexOf(x) > -1 Then  'test each character to extract the numbers
            y = y & x
        End If
    Next

    ...
于 2014-01-20T11:32:00.983 に答える