Results 1 to 7 of 7

Thread: Change combobox height

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    14

    Change combobox height

    I would like to change the height of the standard VB combo box. This is the actual height property of the control not the height of the dropdown list. It defaults to 315 twips and I would like to be able to adjust the height to fit inside the cell of a flexgrid.

    I have tried the Movewindow API. I can get it to work for other controal and to change the height of the Combos dropdown list.

    Is it possible to change the actual height of the Combo Box control.
    Thanks and Good Luck!

    zemp

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    The combobox fits already doesn't it?

    Check out the example given in MSDN:

    VB Code:
    1. Option Explicit
    2.  
    3.       Private Sub Form_Unload(Cancel As Integer)
    4.           If IsHooked Then
    5.              Unhook   ' Stop checking messages.
    6.           End If
    7.       End Sub
    8.  
    9.       Private Sub MSFlexGrid1_MouseUp(Button As Integer, _
    10.          Shift As Integer, x As Single, y As Single)
    11.           Static CurrentWidth As Single
    12.           ' Check to see if the Cell's width has changed.
    13.           If MSFlexGrid1.CellWidth <> CurrentWidth Then
    14.               Combo1.Width = MSFlexGrid1.CellWidth
    15.               CurrentWidth = MSFlexGrid1.CellWidth
    16.           End If
    17.       End Sub
    18.  
    19.       Private Sub Form_Load()
    20.           gHW = MSFlexGrid1.hWnd
    21.           Hook   ' Start checking messages.
    22.           MSFlexGrid1.AllowUserResizing = flexResizeColumns
    23.           MSFlexGrid1.Cols = 4
    24.           MSFlexGrid1.Rows = 6
    25.           MSFlexGrid1.RowHeightMin = Combo1.Height
    26.           Combo1.Visible = False
    27.           Combo1.ZOrder (0)
    28.           Combo1.Width = MSFlexGrid1.CellWidth
    29.           ' Load the ComboBox's list.
    30.           Combo1.AddItem "Some text"
    31.           Combo1.AddItem "Some more text"
    32.           Combo1.AddItem "Still more text"
    33.           Combo1.AddItem "Yet even more text"
    34.           Combo1.AddItem "Way more text than that"
    35.       End Sub
    36.  
    37.  
    38.       Private Sub MSFlexGrid1_Click()
    39.           ' Position and size the ComboBox, then show it.
    40.           Combo1.Width = MSFlexGrid1.CellWidth
    41.           Combo1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left
    42.           Combo1.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top
    43.           Combo1.Text = MSFlexGrid1.Text
    44.           Combo1.Visible = True
    45.       End Sub
    46.  
    47.       Private Sub Combo1_Click()
    48.           ' Place the selected item into the Cell and hide the ComboBox.
    49.           MSFlexGrid1.Text = Combo1.Text
    50.           Combo1.Visible = False
    51.       End Sub
    52.  
    53.  
    54.  
    55. On the Project menu, add a new Module and insert the following code:
    56.  
    57.  
    58.       Option Explicit
    59.  
    60.       Declare Function CallWindowProc Lib "user32" Alias _
    61.          "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
    62.          ByVal hWnd As Long, ByVal Msg As Long, _
    63.          ByVal wParam As Long, ByVal lParam As Long) As Long
    64.  
    65.       Declare Function SetWindowLong Lib "user32" Alias _
    66.          "SetWindowLongA" (ByVal hWnd As Long, _
    67.          ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    68.  
    69.       Private Const GWL_WNDPROC = -4
    70.       Private IsHooked As Boolean
    71.       Private Const WM_SIZE = &H5
    72.       Private Const WM_PAINT = &HF
    73.       Private lpPrevWndProc As Long
    74.       Public gHW As Long
    75.  
    76.       Public Sub Hook()
    77.           If IsHooked Then
    78.           ' Do not hook it twice without unhooking,
    79.           ' or you will not be able to unhook it.
    80.           Else
    81.           lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, _
    82.              AddressOf WindowProc)
    83.           IsHooked = True
    84.           End If
    85.       End Sub
    86.  
    87.       Public Sub Unhook()
    88.           Dim temp As Long
    89.           temp = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
    90.           IsHooked = False
    91.       End Sub
    92.  
    93.       Function WindowProc(ByVal hw As Long, ByVal uMsg As _
    94.          Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    95.           WindowProc = CallWindowProc(lpPrevWndProc, hw, _
    96.              uMsg, wParam, lParam)
    97.           ' The interior of the control is repainted, but not resized.
    98.           If uMsg = WM_SIZE Or uMsg = WM_PAINT Then
    99.              Form1.Combo1.Width = Form1.MSFlexGrid1.CellWidth
    100.              Form1.Combo1.Left = Form1.MSFlexGrid1.CellLeft + _
    101.                 Form1.MSFlexGrid1.Left
    102.              Form1.Combo1.Top = Form1.MSFlexGrid1.CellTop + _
    103.                 Form1.MSFlexGrid1.Top
    104.           End If
    105.       End Function

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    14
    Yes it will fit if the grid rowheight is set to 315 or the combo box height. But this can reduce the number of rows that are visible at once. I would like to have the row height set at the standard textbox height of 285 or less. Basically I don't want to be dependant on the combo box height.
    Thanks and Good Luck!

    zemp

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Here is how to change the ComboBox height. Set the lParam value to the desired height (in pixels). You may have to adjust the font size as well.

    VB Code:
    1. Private Const CB_SETITEMHEIGHT = &H153
    2.  
    3. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    4. (ByVal hwnd As Long, ByVal wMsg As Long, _
    5. ByVal wParam As Long, lParam As Any) As Long
    6.  
    7. Call SendMessage(Combo1.hwnd, CB_SETITEMHEIGHT, -1&, ByVal 10& )

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    14
    That's great. That's what I am after.

    Next Question. What parameters do I need to change in order to control the height. The above code reduces that size to 240. Is that the only option or can I set it to anything. If I can set it to anything how is it done?
    Thanks and Good Luck!

    zemp

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Set the lParam value to the desired height (in pixels).
    It looks like the smallest size possible is 90 twips.

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    14
    Thanks, I was still trying to set the lParam to a value in twips.

    Works great now, Thank you very much.
    Thanks and Good Luck!

    zemp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width