Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


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

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_GETDROPPEDWIDTH = &H15F
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
	Else
		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, _
		CB_SETDROPPEDWIDTH, NewWidthPixel, 0)
	If lRetVal <> CB_ERR Then
		SetDropdownWidth = True
	Else
		SetDropdownWidth = False
	End If
End Function
Rajeev Madnawat
 
Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date