1

radtextboxesユーザーがエンターキーを押したときと、このコード行のテレリック解釈を探しているときとの間でフォーカスを管理するための部分クラスが必要ですtbs(i).KeyDown += New KeyEventHandler(AddressOf textBoxes_KeyDown)。助けてください。

Partial Public Class MstFileTruck Inherits Form

    Private tbs() As Telerik.WinControls.UI.RadTextBox

    Public Sub New()
        InitializeComponent()
        tbs = New Telerik.WinControls.UI.RadTextBox() {txtTruckNumber,   txtRegistrationNumber, txtOwnerName}
        For i As Integer = 0 To tbs.Length - 1
            tbs(i).Tag = i
            tbs(i).KeyDown += New KeyEventHandler(AddressOf textBoxes_KeyDown)
            '    'tbs(i).IsHandleCreated += New KeyEventArgs(Keys.Enter) '(AddressOf textBoxes_KeyDown)
            '    tbs(i).RootElement.KeyDownEvent.EventName(textBoxes_KeyDown) '= New KeyEventArgs(AddressOf   Telerik.WinControls.UI.RadTextBoxElement.KeyDownEvent.EventName(textBoxes_KeyDown(tbs, RootRadElement.KeyDownEvent))) '(AddressOf textBoxes_KeyDown)
        Next
        tbs(0).Focus()
    End Sub

    Private Sub textBoxes_KeyDown(sender As Object, e As KeyEventArgs)
        Dim tb As Telerik.WinControls.UI.RadTextBox = TryCast(sender, Telerik.WinControls.UI.RadTextBox)
        If tb IsNot Nothing Then
            If e.KeyCode = Keys.Enter Then
                Dim tag As Integer = CInt(tb.Tag)
                If tag = 2 Then
                    tbs(0).Focus()
                Else
                    tbs(tag + 1).Focus()
                End If
            End If
        End If
    End Sub
End Class
4

1 に答える 1

0

あなたのコードが何をすべきかよくわかりません。イベント サブスクリプションが機能するかどうかもわかりませんが、RadTextBox の 2 つのインスタンス間でフォーカスを切り替える方法を次に示します。

 Private Sub RadTextBox_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles RadTextBox1.KeyDown, RadTextBox2.KeyDown
    If e.KeyCode = Keys.Enter Then
        Dim tb As RadTextBox = DirectCast(sender, RadTextBox)
        If tb.Name = "RadTextBox1" Then
            RadTextBox2.TextBoxElement.Focus()
        Else
            RadTextBox1.TextBoxElement.Focus()
        End If
    End If
End Sub

VB でイベントをサブスクライブする別の方法は次のとおりです。

        AddHandler RadTextBox1.KeyDown, AddressOf RadTextBox_KeyDown

        Private Sub RadTextBox_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs)
           'your code here
        End Sub

.vb ファイルのように見えるはずのコード全体を次に示します。

Imports Telerik.WinControls.UI

Public Class Form1

Public Sub New()

    ' This call is required by the designer.
    InitializeComponent()

    AddHandler RadTextBox1.KeyDown, AddressOf RadTextBox_KeyDown
End Sub


Private Sub RadTextBox_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles RadTextBox1.KeyDown, RadTextBox2.KeyDown
    If e.KeyCode = Keys.Enter Then
        Dim tb As RadTextBox = DirectCast(sender, RadTextBox)
        If tb.Name = "RadTextBox1" Then
            RadTextBox2.TextBoxElement.Focus()
        Else
            RadTextBox1.TextBoxElement.Focus()
        End If
    End If
End Sub

クラス終了

于 2012-06-08T14:14:05.847 に答える