0
我試圖通過帶有箭頭鍵的控件進行導航(上/下)。
要嘗試我的示例,只需創建一個新的form1並將其粘貼到它。使用vb.net中的箭頭鍵導航
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim tb As New TextBox
Dim cb As New CheckBox
Dim cbb As New ComboBox
Dim b1 As New Button
Dim b2 As New Button
With Me
.KeyPreview = True
.Size = New Size(350, 200)
With .Controls
.Add(tb)
With tb
.TabIndex = 0
.Location = New Point(95, 20)
.Text = "This is"
End With
.Add(cb)
With cb
.TabIndex = 1
.Location = New Point(95, 50)
.Checked = True
.Text = "Example checkbox"
.AutoSize = True
End With
.Add(cbb)
With cbb
.TabIndex = 2
.Location = New Point(95, 80)
.Text = "an Example"
.DropDownStyle = ComboBoxStyle.DropDownList
End With
.Add(b1)
With b1
.TabStop = False
.Location = New Point(90, 130)
.Text = "Nothing"
End With
.Add(b2)
With b2
.TabStop = False
.Location = New Point(170, 130)
.Text = "Exit"
AddHandler b2.Click, AddressOf b2_Click
End With
End With
End With
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Up Then
e.Handled = True
Me.SelectNextControl(Me.ActiveControl, False, True, True, True)
End If
If e.KeyCode = Keys.Down Then
e.Handled = True
Me.SelectNextControl(Me.ActiveControl, True, True, True, True)
End If
End Sub
Private Sub b2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Me.Close()
End Sub
End Class
會發生什麼情況?
當啓動一個程序並用箭頭導航時,在控件周圍沒有'焦點矩形',並且在某些情況下,將「運行結束」聚焦到帶有tabstop = false的控件。
但是......
如果我通過控制與TAB鍵一次傳球后的箭導航變好,焦點矩形出現的,一切都OK。
這裏有什麼問題? 在程序啓動後立即使用箭頭進行導航的操作與使用製表鍵相同?
的可能重複[爲什麼焦點矩形不顯示,直到Tab鍵按下?(http://stackoverflow.com/questions/9226433/why-is-focus-rectangle-not -show-until-tab-key-pressed) –
現在看,可能是重複的,但這裏是完全可行的代碼,用於調查,我的示例不包含導致問題的單選按鈕。還有Windows 7! –
看看建議的修復是否有效,他們說這是導致問題的用戶設置 –