Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to drop a TComboBox up instead of down Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
27-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
81
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

You know how when you open a TComboBox that is near the bottom of the physical 
screen, Windows places the list above the ComboBox rather than below. Is there any 
way in Delphi to force that behavior? In other words, I'm trying to come up with a 
drop-up TComboBox.

Answer:

Here is some code that may help you:

1   { ... }
2   cbxMaxWidth: integer;
3   
4   procedure pmAdjustDropList(var Msg: TMessage); message WM_USER + 1800;
5   { ... }
6   
7     procedure TForm1.pmAdjustDropList(var Msg: TMessage); {WM_USER + 1800;}
8     var
9       LHnd: HWnd;
10      rct: TRect;
11      pt: TPoint;
12      x: integer;
13    begin
14      x := ComboBox1.Height + 1;
15      ComboBox1.Perform(CB_GETDROPPEDCONTROLRECT, 0, longint(@rct));
16      pt := Point(rct.Left + 1, rct.Top + x);
17      {Gets the handle of the window containing the pt}
18      LHnd := WindowFromPoint(pt);
19      rct.Left := rct.Right - cbxMaxWidth; {cbxMaxWidth is maximum width for box}
20      if rct.Right - rct.Left > ComboBox1.Width then
21      begin
22        {Up with right side of combobox}
23        pt := ComboBox1.ScreenToClient(rct.BottomRight);
24        OffsetRect(rct, ComboBox1.Width - (pt.x), x);
25        MoveWindow(LHnd, rct.Left, rct.Top, rct.Right - rct.Left, rct.Bottom - 
26  rct.Top, true);
27      end;
28    end;
29  
30    procedure TForm1.ComboBox1DropDown(Sender: TObject);
31    begin
32      PostMessage(Handle, WM_USER + 1800, 0, 0);
33    end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC