Odd ComboBox behavior on resize

前端 未结 3 996
孤街浪徒
孤街浪徒 2020-12-20 20:25

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  
O         


        
相关标签:
3条回答
  • 2020-12-20 21:06

    When the form loads, ComboTest gets executed, and you see a '6', however when you resize it does not show the new data, sounds like you need to refresh the combo box, regardless of the resize or not.

    Try uxComboBox.Refresh() immediately after the line uxComboBox.Items.AddRange.

    And after the line 'ComboTest', set the selected index to 0 uxComboBox.Index = 0 also.

    Hope this helps, Best regards, Tom.

    0 讨论(0)
  • 2020-12-20 21:08

    I am using windows 10 and Visual Studio 2017. It appears that this bug is still around. With Hans Passant's answer above I worked around the problem in this way.

    I had a combo as a control anchored left and right so it stretched when the form expanded. When the screen expanded, the combobox text was highlighted as if it had got focus even though it hadn't.

    As a work around I took one of the anchors off and added it to text box that was next to it. Now my combo box doesn't expand with the screen, the text box does instead. I know its not a fix all solution but it may help someone in a similar situation to sort the problem.

    0 讨论(0)
  • 2020-12-20 21:10

    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.

    0 讨论(0)
提交回复
热议问题