2012-06-08 39 views
1

我想要一個部分班級來管理我的焦點,當用戶按下Enter鍵時,我正在尋找telerik對這行代碼的解釋tbs(i).KeyDown += New KeyEventHandler(AddressOf textBoxes_KeyDown)任何想法。請幫忙。Telerik版本的system.windows.text代碼

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 
+0

從什麼我記得去年使用Telerik的時候,通常你不需要做很多調整來使用他們的控制。我相信你正在尋找的引用是System.Windows.UIElements或者這些行的東西。 – Tony318

回答

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 

末級
+0

任何想法,我可以放置此代碼,因爲當我把這個代碼放在我的窗體的類下我的窗體有一個重大錯誤,它說太多的分類我可以將代碼複製到Form.Designer代碼?在哪裏cxdan我複製代碼 –

+0

創建一個窗體並在其中添加兩個文本框,即RadTextBox1和RadTextBox2。打開Form1.vb並使其看起來像上面我的答案中的最後一個代碼片段。 – checho