Solved

Panel as popup menu

Posted on 2004-04-24
12
1,771 Views
Last Modified: 2012-06-27
I want to add to my application a panel with some components on it and I want this panel have a popup menu behaviour (when a mouse button is pressed over any component except my panel its visible property will be changed to false). how can I know when the user clicks a components (and the component name) without writing the OnClick events for every component.

is possible to add components to a popup menu?
0
Comment
Question by:ronnix
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10906798
Try
procedure TForm1.Panel1Exit(Sender: TObject);
begin
Panel1.Visible := False;
end;
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10907197
Not sure if this is what you are looking for or not:

for this example, i added a TPopupmenu, and assigned each of the components (on the panel) PopupMenu property to this popup menu.

Then I added two Popup menu items

Hide
Show All

And their events

procedure TForm1.Hide1Click(Sender: TObject);
begin
if TPopupMenu(TMenuItem(Sender).GetParentComponent).PopupComponent is TControl then
  if TControl(TPopupMenu(TMenuItem(Sender).GetParentComponent).PopupComponent).Visible = True then
   TControl(TPopupMenu(TMenuItem(Sender).GetParentComponent).PopupComponent).Visible:= False
  else
   TControl(TPopupMenu(TMenuItem(Sender).GetParentComponent).PopupComponent).Visible:= True;
end;

procedure TForm1.ShowAll1Click(Sender: TObject);
var
 I: Integer;
begin
 for I:= 0 to Panel1.ControlCount - 1 do
  if  not Panel1.Controls[I].Visible then
   Panel1.Controls[I].Visible:= True;
end;


Shane
0
 

Author Comment

by:ronnix
ID: 10908611
Sorry, but this is not what I'm looking for. It's my fault because I didn't formulated my question corectly.
Because I don't know if it is possible to insert some components into a popupmenu (such as a listbox and some buttons) I put a panel on my form with some components, this panel "being" my popupmenu. How can I know if the user clicks any component on the screen except my panel and its components so that I can hide it. I want to do something like the list in Delphi that popups and you can select any property or method of a component or something else. It is visible while you select any item in the list but when you click any area on the screen it disappears.

Hope you understand what I mean
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:shaneholmes
ID: 10908695
Like this maybe

TForm1 = class(TForm)
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
    procedure SelectItem(Sender: Tobject);
  public
    { Public declarations }
  end;



procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
 ListBox1: TListBox;
begin
 if ssRight in Shift then
 begin
   ListBox1:= TListBox.Create(Self);
   ListBox1.Parent:= Self;
   ListBox1.Left:= X;
   ListBox1.Top:= Y;
   ListBox1.Items.Add('Item1');
   ListBox1.OnClick:= SelectItem;
 end;
end;

procedure TForm1.SelectItem(Sender: Tobject);
begin
 // do something with selection
 // TListBox(Sender).Items[TListBox(Sender).ItemIndex]
  TListBox(Sender).Free;
end;

Shane
0
 
LVL 17

Expert Comment

by:mokule
ID: 10908700

So do it like this

procedure TForm1.FormClick(Sender: TObject);
begin
Panel1.Visible := False;
end;
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10908702
Or you could create a Borderless form with a Listbox on it,

then do this

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 if ssRight in Shift then
 begin
  if MyForm.ShowModal = mrOK then
  begin
   // do something with selection
   //MyListBox.Items[MyListBox.ItemIndex]
  end;
 end;
end;


Shane
0
 

Author Comment

by:ronnix
ID: 10912779
:)
I see I was not competely understood.
You say I must write the OnMouseDown event for the form, but what if I click another object on the form? It will not call the main form onmousedown event. And then I must write the onmousedown code for every component on the form, so that when I click it my panel disappear (like a popup menu). So I repeat my question. Is it posible to know when a user clicks a component without writing the onclick event for every object on my form( because all surface of my form is covered with components and I cannot write the onmousedown event for my form bacause it would be vainly?

So, when I press a certain button my panel visible property will become true and when I click everywhere on the desktop except the area ocuppied by my panel its visible property will be changed to false.
0
 
LVL 17

Expert Comment

by:mokule
ID: 10912850

Did You try code from my the very first post?
0
 
LVL 17

Accepted Solution

by:
mokule earned 50 total points
ID: 10912918
I think that this code fulfill all Your requirements.

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnDeactivate := FormDeactivate;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Panel1.Visible := True;
  ActiveControl := Panel1;
end;

procedure TForm1.FormDeactivate(Sender: TObject);
begin
  Panel1.Visible := False;
end;

procedure TForm1.Panel1Exit(Sender: TObject);
begin
  Panel1.Visible := False;
end;

procedure TForm1.FormClick(Sender: TObject);
begin
  Panel1.Visible := False;
end;

0
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 10915790
yes there is a way .. no 2 ways :p


Prepare a windowProc for ur application Handle only WM_MouseButton event and do wot ever u want...

Or

Add a Procedure like

  private
   procedure onMyMouseDown(msg : Tmsg) ; message WM_MBUTTONDOWN;

in ur form object

  procedure tForm1.onMyMouseDown(msg : Tmsg) ;
   begin
     // do wot u want

   end;

get Details about  WM_Mbuttondown from the link below

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/mouseinput/mouseinputreference/mouseinputmessages/wm_mbuttondown.asp


0
 

Author Comment

by:ronnix
ID: 10920178
for non zero
In your code I must declare the procedure like this

procedure OnMouseDown(VAR Msg:Tmsg); message WM_MBUTTONDOWN;
else I get this error: "Invalid message parameter list"

And for this code my application does nothing.
I replaced WM_MButtonDown with WM_LButtonDown and The onmousedown proc is called only when I click the form not when I click other object on it.
I think mokule's answer is the best(just my oppinion), but thanks to all for your answers
0
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 10920561
yw
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question