Print Page | Close Window

How to adjust a ComboBox height

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Controls
Forum Description: Topics Related to Codejock Controls
URL: http://forum.codejock.com/forum_posts.asp?TID=17546
Printed Date: 27 November 2024 at 6:02am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: How to adjust a ComboBox height
Posted By: Norika
Subject: How to adjust a ComboBox height
Date Posted: 09 November 2010 at 11:00pm
Dear Sirs,
 
I want to expand the ComboBox height without change its font size.

So I made a sample program.  Is this a principled approach? (2nd way below sample)


 
Norika
---
Product: Xtreme SuitePro (ActiveX) version 13.4.2
Platform: Windows XP (32bit) - SP 3
Language: Visual Basic 6.0 SP6 

https://forum.codejock.com/uploads/2548/ComboBoxSample.zip - uploads/2548/ComboBoxSample.zip



Replies:
Posted By: Jebo
Date Posted: 10 November 2010 at 2:15pm
> I want to expand the ComboBox height without change its font size.
Oh yes yes yes!!! I WANT IT TOO !!! Clap


-------------
[Sig removed by Admin: Signature can't exceed 40GB]


Posted By: jpbro
Date Posted: 10 November 2010 at 3:52pm
Try this:


Option Explicit

Private Type RECT
   Left As Long
   Top As Long
   Right As Long
   Bottom As Long
End Type

Private Type POINTAPI
   x As Long
   y As Long
End Type

Private Declare Function SendMessageLong Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As Long
Private Declare Function SetWindowPos Lib "user32.dll" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Const GW_CHILD As Long = 5
Private Const CB_SETITEMHEIGHT As Long = &H153

Private Sub Form_Load()
   SetComboHeight 675
End Sub

Private Sub SetComboHeight(ByVal p_HeightTwips As Long)
   Dim l_Hwnd As Long
   Dim lt_EditRect As RECT
   Dim lt_Pt As POINTAPI
   Dim lt_Pt2 As POINTAPI
   Dim l_YOffset As Long
   Dim l_FontHeight As Long
   Dim lo_OldFont As StdFont
     
   On Error GoTo ErrorHandler

   SendMessageLong Me.ComboBox1.hwnd, CB_SETITEMHEIGHT, -1, p_HeightTwips / Screen.TwipsPerPixelY - 6

   l_Hwnd = GetWindow(Me.ComboBox1.hwnd, GW_CHILD)

   If l_Hwnd <> 0 Then
      GetWindowRect l_Hwnd, lt_EditRect
  
      lt_Pt.x = 3
      lt_Pt.y = 1
  
      lt_Pt2.x = lt_EditRect.Right - lt_EditRect.Left - lt_Pt.x * 2
      lt_Pt2.y = lt_EditRect.Bottom - lt_EditRect.Top - 2
  
      Set lo_OldFont = Me.Font
      Set Me.Font = Me.ComboBox1.Font
      l_FontHeight = Me.TextHeight(Me.ComboBox1.Text)
      Set Me.Font = lo_OldFont
     
      l_YOffset = (p_HeightTwips - l_FontHeight) \ 2 \ Screen.TwipsPerPixelY
  
      SetWindowPos l_Hwnd, 0, lt_Pt.x, lt_Pt.y + l_YOffset - 1, lt_Pt2.x + 1, lt_Pt2.y - (l_YOffset - 2), 0
   End If

   Exit Sub
  
  
ErrorHandler:
   Debug.Print Err.Description
End Sub


Seems to work okay for Style = DropDown or Style = DropDownList with EnableMarkup = True.

Haven't tested it extensively, but it should put you on the right track.



-------------
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6



Posted By: Norika
Date Posted: 10 November 2010 at 10:10pm
Dear jpbro,
 
Thank you for advice!
The height of ComboBox was displayed definitely when I tried the code that had you shown, but the rectangle of the pull-down listbox has shortened.
I tried to drew the pull-down list box after your method again, but do not get along well.
Is there any good idea?
 
  
Norika
---
Product: Xtreme SuitePro (ActiveX) version 13.4.2
Platform: Windows XP (32bit) - SP 3
Language: Visual Basic 6.0 SP6 
https://forum.codejock.com/uploads/2548/Adjust_ComboBox_Height_Rev_1.zip - uploads/2548/Adjust_ComboBox_Height_Rev_1.zip



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net