Home > Software engineering > VB, how will the drop-down combobox show more rows. The following figure, by the default line 8 to 1
VB, how will the drop-down combobox show more rows. The following figure, by the default line 8 to 1
Time:09-20
VB, how the combobox dropdown on the number of lines more, below, by the default line 8 to 16 or 20 lines, the original code, thank you!
CodePudding user response:
MoveWindow API to set the height of the combo,
CodePudding user response:
The two way,
First, as the upstairs said, change list height (may need to calculate the correct height), This want to use the method of HOOK can be achieved, the following pictures of "game", there is change drop-down list box width,
Second, enable WinXP Style control Style, so it is the default maximum height 30,
CodePudding user response:
According to the new number of rows, calculate the ComboBox List area the necessary height in pixels, then reset:
Private Type the RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, _ LpRect As Long As the RECT) Private Declare Function ScreenToClientAny Lib "user32" Alias "ScreenToClient" _ (ByVal hWnd As Long, lpPoint As Any) As Long Private Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, _ ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, _ ByVal nHeight As Long, ByVal bRepaint As Long As Long)
'Set a new height for the list area of a ComboBox control ' 'the NEWHEIGHT is measured in pixels
Sub ComboBoxSetHeight (CB As ComboBox, ByVal newHeight As Long) Dim lpRect As the RECT Dim wi As Long
'get combobox rectangle, relative to screen GetWindowRect CB. HWnd lpRect Wi=lpRect. Right - lpRect. Left
'convert to form' s client coordinates ScreenToClientAny CB. Parent. HWnd, lpRect
'to enforce the new height MoveWindow CB. HWnd lpRect. Left, lpRect. Top, wi, newHeight, True