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

End Sub

CodePudding user response:

refer to the second floor Chen8013 response:
this 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,

could you tell me how to achieve the second method VB 6.0? Have a code direct call?

CodePudding user response:

Enable WinXP style, the method also has two:
One is to write a manifest file, baidu method yourself; The second is the realization of WinXP style resources to the program,

The first method is not good: no flexible (every need according to the program file to change the manifest file name and content), to drag a "little tail",
I was using the second method, need to use directly to the project went, I do this resource file can be "general",

In addition to pay attention to:
If you enable the XP style, your program want to in WinXP/Win2003 normal operation, must be in the initialization function called "program entrance",
If your program will only run in Vista or higher version of the system, so whether can the initialization function,

A simple initialization code shown in the diagram below,
If a program from a "window" to start, must be in Form_Initialize () call (as long as the startup form a line),
If from the Sub Main (), then call, in the process of the Main
"Call InitCommonControls" must be in any form (including with display MsgBox message window) before loading,
Failure form loads, the program directly by end (without any hint),
In short, make your program executed first initialization function call,
The below "save as" rar file, use open WinRAR, can extract out my XP_Style. Res file.

CodePudding user response:

Forgot to say:
WinXP style only enrolled into exe run after effective, there is no effect in the IDE,

If you want to be in the "design" effect at the time, can give the VB6. Write a manifest exe files,
, I try to write after the manifest file properties window in the "color", there is a white board,

CodePudding user response:

Have will spend with three building code collection,