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 pop up a TComboBox at the current caret position in a TMemo 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
Reporting /Printing
Language
Delphi 2.x
Views
105
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I would like to pop up a TComboBox at the caret position on a TMemo when the key 
that is pressed is a full stop (.). Has anyone got any code for this?

Answer:

1   unit CBoxInMemo;
2   
3   interface
4   
5   uses
6     Windows, Classes, Controls, Graphics, Forms, StdCtrls;
7   
8   type
9     TFrmCboxInMemo = class(TForm)
10      Button1: TButton;
11      Memo1: TMemo;
12      Label1: TLabel;
13      ComboBox1: TComboBox;
14      procedure Button1Click(Sender: TObject);
15      procedure ComboBox1Exit(Sender: TObject);
16      procedure ComboBox1Click(Sender: TObject);
17    private
18      { Private declarations }
19    public
20      { Public declarations }
21    end;
22  
23  var
24    FrmCboxInMemo: TFrmCboxInMemo;
25  
26  implementation
27  
28  {$R *.DFM}
29  
30  procedure TFrmCboxInMemo.Button1Click(Sender: TObject);
31  var
32    clientPos: TPoint;
33    lineHeight: Integer;
34    tmpFont: TFont;
35  begin
36    GetCaretPos(clientPos);
37    {Use the following calculation of line height only if you want your combobox
38    to appear below the char position you are referencing.}
39    tmpFont := Canvas.Font;
40    Canvas.Font := Memo1.Font;
41    lineHeight := Canvas.TextHeight('Xy');
42    Canvas.Font := tmpFont;
43    with ComboBox1 do
44    begin
45      {Adjustment of Top by lineHeight only necessary if combobox is to appear below 
46  line.}
47      Top := clientPos.Y + Memo1.Top + lineHeight;
48      Left := clientPos.X + Memo1.Left;
49      Visible := true;
50      SetFocus;
51    end;
52  end;
53  
54  procedure TFrmCboxInMemo.ComboBox1Exit(Sender: TObject);
55  begin
56    ComboBox1.Visible := false;
57  end;
58  
59  procedure TFrmCboxInMemo.ComboBox1Click(Sender: TObject);
60  begin
61    ComboBox1.Visible := false;
62  end;
63  
64  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