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 LongPrivate Const CB_GETDROPPEDWIDTH = &H15FPrivate Const CB_SETDROPPEDWIDTH = &H160Private Const CB_ERR = -1Public 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	Else		GetDropdownWidth = 0	End IfEnd FunctionPublic Function SetDropdownWidth(cboHwnd As _	Long, NewWidthPixel As Long) As Boolean	Dim lRetVal As Long	' *** To set combo box drop-down width ***	lRetVal = SendMessage(cboHwnd, _		CB_SETDROPPEDWIDTH, NewWidthPixel, 0)	If lRetVal <> CB_ERR Then		SetDropdownWidth = True	Else		SetDropdownWidth = False	End IfEnd Function
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS