2

テキストボックス、numericupdown コントロール、そして現在はコンボボックスで構成される機能的な GUI に 3 つのコンボボックスを組み込もうとしています。
これらのフォームでは、上下のキーを使用してキーボード (me.selectnextcontrol) を使用したナビゲーションがあります。
何が起こるのですか?
これらの GUI に初めて足を踏み入れると、すべてが正常に機能し、期待どおりにキーボードで上下に移動できます。

GUIの真ん中にあり、次のように設定されているコンボボックスを編集すると問題が発生します。

    mycombo.AutoCompleteMode = AutoCompleteMode.SuggestAppend
    mycombo.AutoCompleteSource = AutoCompleteSource.CustomSource
    mycombo.AutoCompleteCustomSource = myAutoCompleteStringCollection

問題は、これらのコンボボックスに戻ったときに、コンボボックスがそれ自体の目的 (インデックスの変更) のためにそれらを取得するため、ナビゲーション ループがキープレス (上または下のキー) を取得しないことです。

私はmycombo.AutoCompleteSource = AutoCompleteSource.CustomSourcecombobox_Leaveの後に試してみましたが、それは望ましくないオートコンプリートをオフにします。

質問:
ここでは、プログラムの開始時と同じようにモードで使用した後に説明されたコンボボックスを設定することは可能ですか?もう一度編集します。

EDITED:これは問題を示す簡単な例です:

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 cbb As New ComboBox
    Dim tbb As New TextBox
    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(cbb)
            With cbb
                .TabIndex = 1
                .Items.AddRange(New String() {"alabama", "africa", "australia", "grenland"})
                .Location = New Point(95, 50)
                .Text = "an Example"
                .DropDownStyle = ComboBoxStyle.DropDown
                .AutoCompleteMode = AutoCompleteMode.SuggestAppend
                .AutoCompleteSource = AutoCompleteSource.ListItems
            End With
            .Add(tbb)
            With tbb
                .TabIndex = 2
                .Location = New Point(95, 80)
                .Text = "textbox"
            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

このプログラムを開始すると、すべてのコントロールをキーダウン矢印で数回通過します。次に、コンボボックスで停止し、文字「a」を入力してから、キーダウン矢印で再度ナビゲートしてみてください。

4

1 に答える 1

1
Public Class Form1

    Private tb As New TextBox
    Private cbb As New ComboBox
    Private tbb As New TextBox
    Private b1 As New Button
    Private b2 As New Button

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        AddHandler cbb.PreviewKeyDown, AddressOf cbb_PreviewKeyDown
        AddHandler tb.PreviewKeyDown, AddressOf tb_PreviewKeyDown
        AddHandler tbb.PreviewKeyDown, AddressOf tbb_PreviewKeyDown

        Me.Size = New Size(350, 200)

        With tb
            .Parent = Me
            .TabIndex = 0
            .Location = New Point(95, 20)
            .Text = "This is"
        End With

        With cbb
            .Parent = Me
            .TabIndex = 1
            .Items.AddRange(New String() {"alabama", "africa", "australia", "grenland"})
            .Location = New Point(95, 50)
            .Text = "an Example"
            .DropDownStyle = ComboBoxStyle.DropDown
            .AutoCompleteMode = AutoCompleteMode.SuggestAppend
            .AutoCompleteSource = AutoCompleteSource.ListItems
        End With

        With tbb
            .Parent = Me
            .TabIndex = 2
            .Location = New Point(95, 80)
            .Text = "textbox"
        End With

        With b1
            .Parent = Me
            .TabStop = False
            .Location = New Point(90, 130)
            .Text = "Nothing"
        End With

        With b2
            .Parent = Me
            .TabStop = False
            .Location = New Point(170, 130)
            .Text = "Exit"
            AddHandler b2.Click, AddressOf b2_Click
        End With

    End Sub

    Private Sub tb_PreviewKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs)
        If e.KeyCode = Keys.Up Then tbb.Focus()
        If e.KeyCode = Keys.Down Then cbb.Focus()
    End Sub

    Private Sub cbb_PreviewKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs)
        If e.KeyCode = Keys.Up Then
            cbb.AutoCompleteMode = AutoCompleteMode.None
            tb.Focus()
            cbb.AutoCompleteMode = AutoCompleteMode.SuggestAppend
            If Not cbb.Items.Contains(cbb.Text) Then cbb.Text = ""
        End If
        If e.KeyCode = Keys.Down Then
            cbb.AutoCompleteMode = AutoCompleteMode.None
            tbb.Focus()
            cbb.AutoCompleteMode = AutoCompleteMode.SuggestAppend
            If Not cbb.Items.Contains(cbb.Text) Then cbb.Text = ""
        End If
    End Sub

    Private Sub tbb_PreviewKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs)
        If e.KeyCode = Keys.Up Then cbb.Focus()
        If e.KeyCode = Keys.Down Then tb.Focus()
    End Sub

    Private Sub b2_Click()
        Me.Close()
    End Sub
End Class

私はあなたのコードを修正しました。そして今、それは働いています。:)

于 2013-02-08T18:20:18.683 に答える