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 display a popup menu at a certain position in a TTreeView 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
31-Oct-02
Category
VCL-Menu
Language
Delphi All Versions
Views
132
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I want to get the exact position (in terms of x, y coordinates) within a treeview. 
The reason is that I want a popup menu to appear after a certain keypress.

Answer:

Solve 1:
1   
2   procedure TForm1.TreeView1KeyDown(Sender: TObject; var Key: Word; Shift: 
3   TShiftState);
4   var
5     rect: TRect;
6   begin
7     if assigned(TreeView1.Selected) then
8     begin
9       rect := TreeView1.selected.DisplayRect(true);
10      {Because the popup function pops up on the screen, you need to add the form
11  	  coordinates, the treeview coordinates, and then the displayrect coordinates of 
12  	  the item.}
13      PopupMenu1.Popup(Form1.Top + TreeView1.Top + rect.Top,
14        Form1.Left + TreeView1.Left + rect.Left);
15    end;
16  end;



Solve 2:

Here's an example of a popup menu that launches when a user clicks on a node in a 
TTreeView.
17  
18  procedure TfrmExplorer.TreeViewMouseDown(Sender: TObject; Button: TMouseButton;
19    Shift: TShiftState; X, Y: Integer);
20  var
21    P: TPoint;
22  begin
23    if Button <> mbRight then
24      exit;
25    TreeMenu.AutoPopup := False;
26    if TreeView.GetNodeAt(X, Y) <> nil then
27    begin
28      TreeView.Selected := TreeView.GetNodeAt(X, Y);
29      P.X := X;
30      P.Y := Y;
31      P := TreeView.ClientToScreen(P);
32      TreeMenu.Popup(P.X, P.Y);
33    end;
34  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