Jdavis Posted January 18, 2009 Share Posted January 18, 2009 I wasn't able to find in way of a solution for this, but was hoping someone could point me in the right direction. Is it possible to have the opened list of items in a Combo control maximized to be able to show the longest item in the view when the Combo control itself has a width that is shorter? For example, if you were to create your control with... $myComboBox= GUICtrlCreateCombo( "This a really long item in my combo box that is much wider than the width of the combo box", 0, 0, 50, 0 ) In my understanding, when you open this combo box it won't display this entire item, but instead the opened view will only have the same width as the width of the control and any items in the opened view will simply just be cut-off when they exceed that width. I was hoping there'd be a way that when a combo control is opened that the open view could be made to be as wide as the longest item in the list. Link to comment Share on other sites More sharing options...
smashly Posted January 19, 2009 Share Posted January 19, 2009 Hi,#include <GUIConstantsEx.au3> #Include <GuiComboBox.au3> Opt('MustDeclareVars', 1) Example() Func Example() Local $msg, $Combo GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered $Combo = GUICtrlCreateCombo("This a really long item in my combo box that is much wider than the width of the combo box", 10, 10) ; create first item ConsoleWrite(_GUICtrlComboBox_GetLBTextLen($Combo, 0) & @LF) _GUICtrlComboBox_SetDroppedWidth($Combo, _GUICtrlComboBox_GetLBTextLen($Combo, 0) * 4.8) GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc Cheers Link to comment Share on other sites More sharing options...
Jdavis Posted January 20, 2009 Author Share Posted January 20, 2009 (edited) Thanks! That sure works well. After a bit of googling, I stumbled on to this page for undering those various functions:http://msdn.microsoft.com/en-us/library/a66b856s(VS.80).aspxI was curious, though, why the 4.8? Does this in some way to relate to the width of a pixel? I only ask because I was trying to think of a way to always have the width of the open list always be just large enough to accomodate the biggest string. So, in my particular case, I was doing something to the effect of:For $i = 1 To UBound( $inputFromINI ) - 1 GUICtrlSetData( $myComboBox, $inputFromINI[$i] ) If StringLen( $inputFromINI[$i] ) > $longestString Then $longestString = $inputFromINI[$i] $longestStringIndex = $i EndIf Next _GUICtrlComboBox_SetDroppedWidth( $myComboBox, _GUICtrlComboBox_GetLBTextLen( $myComboBox, $longestStringIndex ) )However, this doesn't give the desired result. I imagine there's something I'm not quite grasping about how those functions are intended to work? Edited January 20, 2009 by Jdavis Link to comment Share on other sites More sharing options...
smashly Posted January 20, 2009 Share Posted January 20, 2009 Thanks! That sure works well. After a bit of googling, I stumbled on to this page for undering those various functions: http://msdn.microsoft.com/en-us/library/a66b856s(VS.80).aspx I was curious, though, why the 4.8? Does this in some way to relate to the width of a pixel? I only ask because I was trying to think of a way to always have the width of the open list always be just large enough to accomodate the biggest string. So, in my particular case, I was doing something to the effect of: For $i = 1 To UBound( $inputFromINI ) - 1 GUICtrlSetData( $myComboBox, $inputFromINI[$i] ) If StringLen( $inputFromINI[$i] ) > $longestString Then $longestString = $inputFromINI[$i] $longestStringIndex = $i EndIf Next _GUICtrlComboBox_SetDroppedWidth( $myComboBox, _GUICtrlComboBox_GetLBTextLen( $myComboBox, $longestStringIndex ) ) However, this doesn't give the desired result. I imagine there's something I'm not quite grasping about how those functions are intended to work?Your welcome, _GUICtrlComboBox_GetLBTextLen() function returns the number characters in the string. I just did a crude calculation of 4.8 pixels for a characters width. But the _GUICtrlComboBox_SetDroppedWidth() function works with pixels. You could use different ways to get the true length of pixels of the longest string. _WinAPI_GetTextExtentPoint32() function can return the length a string in pixels. Also there are some GDI+ functions that can calculate the length of a string in pixels based of the the text attributes, eg: font type, font size, weight, font attributes (italic, bold, underline, strike) Cheers Link to comment Share on other sites More sharing options...
kjcdude Posted February 7, 2009 Share Posted February 7, 2009 Function that should work. _maxcomboboxdrop($COMBOBOXNAME) Func _maxcomboboxdrop($box1) $cl2 = 0 $list2 = _GUICtrlComboBox_GetListArray($box1) for $t = 1 to $list2[0] $l2 = _GUICtrlComboBox_GetLBTextLen($box1, $t) if $l2 > $cl2 Then $cl2 = $l2 EndIf Next _GUICtrlComboBox_SetDroppedWidth($box1, $cl2 * 5.8) EndFunc Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now