ImageCombo控件==> 如何用代码加宽它的下拉框宽度.

解决方案 »

  1.   

    很难。ImageCombo包含了一个ComboBox,而它的下拉部份是没有句柄的。
      

  2.   

    http://www.vbaccelerator.com/home/vb/Tips/Change_the_drop-down_width_of_a_combo_box/article.asp
      

  3.   

    哦,原来SendMessage可以用这个参数(CB_SETDROPPEDWIDTH)来设置ComboBox下拉框的宽度。
    谢谢楼上。
      

  4.   

    '我给段完整的代码吧.
    '申明:(我是放类模块中的.)
    '加长加宽Combo的声明:
      '加长Combo 的调用代码: Call SetComboHeight(Combo1, 270)
      '加宽Combo 的调用代码: Call SetComboWidth(Combo1, 270)
      '加长的声明:
      Private Declare Function MoveWindow Lib "user32" _
      (ByVal hwnd As Long, ByVal X As Long, ByVal Y As _
      Long, ByVal nWidth As Long, ByVal nHeight As Long, _
      ByVal bRepaint As Long) As Long
      '加宽的声明
      'Public Declare Function SendMessage Lib "user32" _
      Alias "SendMessageA" (ByVal hwnd As Long, _
      ByVal wMsg As Long, ByVal wParam As Long, _
      lParam As Long) As Long
      Const LB_FINDSTRING = &H18F
      Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
            (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
             lParam As Any) As Long  Const CB_SETDROPPEDWIDTH = &H160
      '加长的函数:
      Public Sub SetComboHeight(oComboBox As ComboBox, lNewHeight As Long)
         Dim oldscalemode As Integer
         'This procedure does not work with frames: you
         'cannot set the ScaleMode to vbPixels, because
         'the frame does not have a ScaleMode Property.
         'To get round this, you could set the parent control
         'to be the form while you run this procedure.
         If TypeOf oComboBox.Parent Is Frame Then Exit Sub
         'Change the ScaleMode on the parent to Pixels.
         oldscalemode = oComboBox.Parent.ScaleMode
         oComboBox.Parent.ScaleMode = vbPixels
         'Resize the combo box window.
         MoveWindow oComboBox.hwnd, oComboBox.Left, _
         oComboBox.Top, oComboBox.Width, lNewHeight, 1
         'Replace the old ScaleMode
         oComboBox.Parent.ScaleMode = oldscalemode
      End Sub
      '加宽的函数:
      Public Sub SetComboWidth(oComboBox As ComboBox, lWidth As Long, Optional Move As Boolean)
         'lWidth 是宽度,单位是 pixels
         SendMessage oComboBox.hwnd, CB_SETDROPPEDWIDTH, lWidth, 0
      End Sub
    '加长加宽Combo的代码结束