Re: Combobox height

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"Michael C" <nospam@xxxxxxxxxx> wrote in message
news:uSFVep5rGHA.4296@xxxxxxxxxxxxxxxxxxxxxxx
<James@xxxxxxx> wrote in message
news:fleac2laudc77snh31mn0b2a0bj8g01s7u@xxxxxxxxxx
For a long time I have been using the following code to control a
comboboxes drop don height

the problem is that itdoes not work of the combobox s in a frame How
come and is there a way arond it

You didn't really try very hard to solve this. A bit of simple debugging
should have had the answer for you in no time. The reason is that
Combo.Parent always returns the form so you're changing the scalemode of the
form not the frame. This immediately struck me as a really bad idea anyway
and doing it correctly fixed the problem. The reason this is a bad idea is
doing this sort of coding it is very easy for your form to get stuck in the
wrong scale mode and for everything to go haywire.

Public Sub SetComboHeight(ByVal Combo As ComboBox, ByVal Height As Long)
Dim L As Long, T As Long, W As Long

L = ScaleX(Combo.Left, Combo.Parent.ScaleMode, vbPixels)
T = ScaleX(Combo.Top, Combo.Parent.ScaleMode, vbPixels)
W = ScaleX(Combo.Width, Combo.Parent.ScaleMode, vbPixels)
MoveWindow Combo.hwnd, L, T, W, Height, 1
End Sub

Other changes I would suggest is to pass the combo box in ByVal and Height
in ByVal, don't bother with the return type if you're not using it and to
get rid of the use of With, it made your code pretty unreadable.

Isn't the coordinate system for a frame control always in twips?
So instead of Combo.Parent.ScaleMode, use vbTwips in the scale conversions.

David


.



Relevant Pages

  • Re: Combobox height
    ... form not the frame. ... The reason this is a bad idea is ... Public Sub SetComboHeight(ByVal Combo As ComboBox, ... L = ScaleX(Combo.Left, Combo.Parent.ScaleMode, vbPixels) ...
    (microsoft.public.vb.general.discussion)
  • Re: Aero Glass Control Text Problem
    ... Dim varLeft As Variant, varTop As Variant ... sngHeight = frmTrans.ScaleY(frmTrans.Height, vbTwips, vbPixels) ... 'Get our frame, because we want to show a frame with this one ... CombineRgn lngRegion, lngNew, lngRegion, RGN_OR ...
    (microsoft.public.vb.general.discussion)
  • Re: api - tracking LostFocus or Exit event of a combobox
    ... I don't have access to the Combobox directly from the Userform; ... window 's class using Spy+, it seems like the combobox doesn't have a window ... assicioted with it (unlike the listbox or a frame). ...
    (microsoft.public.excel.programming)
  • UserForm ComboBox RowSource Problem
    ... On Frame 2 is a ComboBox. ... I am loading this ComboBox with one of 31 named ranges. ... I have a zipped sample which uses only two days not 31. ... TextBoxes changing as they should. ...
    (microsoft.public.excel.programming)
  • Re: api - tracking LostFocus or Exit event of a combobox
    ... I don't have access to the Combobox directly from the Userform; ... window 's class using Spy+, it seems like the combobox doesn't have a window ... assicioted with it (unlike the listbox or a frame). ...
    (microsoft.public.excel.programming)