调整大小时的奇怪组合框行为 [英] Odd ComboBox behavior on resize

查看:46
本文介绍了调整大小时的奇怪组合框行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个问题,当ComboBox控件调整大小时,它会更改其Text值。这是我处理的一些示例代码:

  

的期权显式
的期权严格
$ b公共类FMain
私有子项FMain_Load(ByVal发送者作为对象,ByVal e作为System.EventArgs)处理Me.Load
uxComboBox.DropDownStyle = ComboBoxStyle.DropDown
uxComboBox。 AutoCompleteSource = AutoCompleteSource.ListItems
uxComboBox.AutoCompleteMode = AutoCompleteMode.Suggest

ComboTest()
End Sub

Private Sub ComboTest()
字符串形式的Dim值= 6

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

uxComboBox.Items.AddRange(新字符串(){ 4 9/16, 6 9/16, 7 9/16, 8 9/16})

Dim索引为Integer = uxComboBox.FindStringExact(value )
如果uxComboBox.SelectedIndex索引然后
uxComboBox.SelectedIndex =索引
如果结束

如果uxComboBox.SelectedIndex = -1并且_
不是String.Equals(uxComboBox.Text,value,StringComparison.OrdinalIgnoreCase)然后
uxComboBox.Text =值
结束如果

'取消选择组合框中的文本
'
uxComboBox.Select(0,0)
结束子
结束类

请注意,此表单(FMain)上有一个组合框(uxComboBox),该组合框停靠在顶部。当我运行代码时,我看到组合框的值为 6,这是我期望的。然后,当我调整表单大小时,组合框的值为 6 9/16,这是我期望的值。



可以有人知道为什么会这样吗?有建议的解决方法吗?



谢谢!



Stephen



我认为自Vista以来,该错误就已存在,但Win7并没有解决该错误。没有已知的解决方法。


I have an issue where a ComboBox control will change it's Text value when it is resized. Here is some sample code that I worked up:


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  

Note that this form (FMain) has a single combobox on it (uxComboBox) that is docked to the top. When I run the code I see that the combobox has a value of "6" which is what I would expect. When I then resize the form, the combobox gets a value of "6 9/16" which is what I would NOT expect.

Does anyone know why this happens? Any suggested workarounds?

Thanks!

Stephen

解决方案

Yes, this is a known bug in the native Windows implementation of ComboBox. There's another aspect to this bug. Put a button on your form and give it TabIndex = 0, change the CB's TabIndex to 1. Run it, the button will have the focus. Resize. Note that the ComboBox's text changes as before but now also gets highlighted, as though it has the focus. Even though it hasn't.

I think this bug has been around since Vista, it didn't get fixed in Win7. There's no known workaround for it.

这篇关于调整大小时的奇怪组合框行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆