Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Dec 7, 1998



Application Security Testing: An Integral Part of DevOps

Adjust Combo Box Drop-down Width

Due to limited space on a form, you sometimes must keep the width of combo boxes small. Because a combo box lacks a horizontal scrollbar, some text might remain hidden. Use these functions to retrieve the current size of a drop-down and to resize the drop-down portion of the combo box as needed at run time. Add this code to a BAS module and call it from wherever convenient-perhaps during your Form_Load procedure:
Private Declare Function SendMessage Lib _
	"USER32" Alias "SendMessageA" _
	(ByVal hwnd As Long, ByVal Msg As Long, _
	ByVal wParam As Long, ByVal lParam As _
	Long) As Long
Private Const CB_SETDROPPEDWIDTH = &H160
Private Const CB_ERR = -1

Public Function GetDropdownWidth(cboHwnd As Long) As Long
	Dim lRetVal As Long
	'*** To get the combo box drop-down width. 
	'*** You may use this function if you want 
	'*** to change the width in proportion 
	'*** i.e. double, half, 3/4 of existing width.
	lRetVal = SendMessage(cboHwnd, CB_GETDROPPEDWIDTH, 0, 0)
	If lRetVal <> CB_ERR Then
		GetDropdownWidth = lRetVal
		'Width in pixels
		GetDropdownWidth = 0
	End If
End Function

Public Function SetDropdownWidth(cboHwnd As _
	Long, NewWidthPixel As Long) As Boolean
	Dim lRetVal As Long
	' *** To set combo box drop-down width ***
	lRetVal = SendMessage(cboHwnd, _
	If lRetVal <> CB_ERR Then
		SetDropdownWidth = True
		SetDropdownWidth = False
	End If
End Function
Rajeev Madnawat
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date