调整大小时出现奇怪的ComboBox行为

Ste*_*enM 6 vb.net combobox

我有一个问题,ComboBox控件将在调整大小时更改其Text值.以下是我编写的一些示例代码:


Option Explicit On  
Option Strict On

Public Class FMain  
    Private Sub FMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
        uxComboBox.DropDownStyle = ComboBoxStyle.DropDown  
        uxComboBox.AutoCompleteSource = AutoCompleteSource.ListItems  
        uxComboBox.AutoCompleteMode = AutoCompleteMode.Suggest  

        ComboTest()  
    End Sub  

    Private Sub ComboTest()  
        Dim value As String = "6"  

        uxComboBox.Text = String.Empty  
        uxComboBox.Items.Clear()  

        uxComboBox.Items.AddRange(New String() {"4 9/16", "6 9/16", "7 9/16", "8 9/16"})  

        Dim index As Integer = uxComboBox.FindStringExact(value)  
        If uxComboBox.SelectedIndex  index Then  
            uxComboBox.SelectedIndex = index  
        End If  

        If uxComboBox.SelectedIndex = -1 AndAlso _
           Not String.Equals(uxComboBox.Text, value, StringComparison.OrdinalIgnoreCase) Then  
            uxComboBox.Text = value  
        End If  

        ' unselect the text in the combobox  
        '  
        uxComboBox.Select(0, 0)  
    End Sub  
End Class  
Run Code Online (Sandbox Code Playgroud)

请注意,此表单(FMain)上有一个组合框(uxComboBox),它停靠在顶部.当我运行代码时,我发现组合框的值为"6",这正是我所期望的.当我然后调整表单大小时,组合框的值为"6 9/16",这是我希望的.

有谁知道为什么会这样?任何建议的解决方法?

谢谢!

斯蒂芬

Han*_*ant 5

是的,这是ComboBox的本机Windows实现中的一个已知错误.这个bug有另一个方面.在表单上放一个按钮并将其TabIndex = 0,将CB的TabIndex更改为1.运行它,该按钮将具有焦点.调整.请注意,ComboBox的文本会像以前一样更改,但现在也会突出显示,就好像它具有焦点一样.即使它没有.

我认为这个bug自Vista以来一直存在,它在Win7中没有得到修复.它没有已知的解决方法.