Question and Answer Database FAQ2923D.txt TCombobox drop down size. Category :VCL Platform :All Product :All 32 bit Question: How can I tell the actual size of a TComboBox in it's dropped down state before it drops down? Answer: During the FormShow event, send the combo box a CB_SHOWDROPDOWN message twice, once to drop it down, and once to retract it. Then send a CB_GETDROPPEDCONTROLRECT message, passing the address of a TRect. When the SendMessage call returns, the TRect will contain the rectangle that would enclose the ComboBox in it's dropped down state, relative to the screen. You can then call ScreenToClient to convert the TRect's coordinates to be relative to the client area of the form. Example: var R : TRect; procedure TForm1.FormShow(Sender: TObject); var T : TPoint; begin SendMessage(ComboBox1.Handle, CB_SHOWDROPDOWN, 1, 0); SendMessage(ComboBox1.Handle, CB_SHOWDROPDOWN, 0, 0); SendMessage(ComboBox1.Handle, CB_GETDROPPEDCONTROLRECT, 0, LongInt(@r)); t := ScreenToClient(Point(r.Left, r.Top)); r.Left := t.x; r.Top := t.y; t := ScreenToClient(Point(r.Right, r.Bottom)); r.Right := t.x; r.Bottom := t.y; end; procedure TForm1.Button1Click(Sender: TObject); begin Form1.Canvas.Rectangle(r.Left, r.Top, r.Right, r.Bottom ); end; 7/16/98 4:31:28 PM
Last Modified: 01-SEP-99