Solved

Panel as popup menu

Posted on 2004-04-24
12
1,660 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
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 17

Expert Comment

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

Expert Comment

by:shaneholmes
Comment Utility
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
Comment Utility
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
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
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
Comment Utility

So do it like this

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

Expert Comment

by:shaneholmes
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:ronnix
Comment Utility
:)
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
Comment Utility

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

Accepted Solution

by:
mokule earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
yw
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now