Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Controls
  New Posts New Posts RSS Feed - How to adjust a ComboBox height
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to adjust a ComboBox height

 Post Reply Post Reply
Author
Message
Norika View Drop Down
Groupie
Groupie
Avatar

Joined: 30 November 2006
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote Norika Quote  Post ReplyReply Direct Link To This Post Topic: How to adjust a ComboBox height
    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 

uploads/2548/ComboBoxSample.zip
Back to Top
Jebo View Drop Down
Senior Member
Senior Member


Joined: 27 October 2005
Location: Germany
Status: Offline
Points: 318
Post Options Post Options   Thanks (0) Thanks(0)   Quote Jebo Quote  Post ReplyReply Direct Link To This Post 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]
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
Norika View Drop Down
Groupie
Groupie
Avatar

Joined: 30 November 2006
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote Norika Quote  Post ReplyReply Direct Link To This Post 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 
uploads/2548/Adjust_ComboBox_Height_Rev_1.zip
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.172 seconds.