1

我希望有一个部分类来管理我在radtextboxes用户按下回车键和我正在寻找这行代码的 Telerik 解释之间的焦点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 实例之间切换焦点:

 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 回答