Discussion:
Delphi : Keep a PopupMenu open after a click?
(too old to reply)
b***@googlemail.com
2009-02-16 18:31:23 UTC
Permalink
Hi,

I am trying to stop my popupmenu from closing when i click it. I know
the simple hack is to just repopup the menu after the click but i
would like to keep the popupmenu structure intact before the click
(i.e. i might have gone down several subitems and i dont believe you
can repopup to the exact subitems state)

I notice TMS software has a component that can do this, but can anyone
save me some money and help me achieve the same thing without having
to buy it?

TAdvStickyPopupMenu -> http://www.tmssoftware.com/site/atbdev10.asp

Regards,

Chris
a***@aol.com
2009-02-17 10:24:03 UTC
Permalink
Post by b***@googlemail.com
I am trying to stop my popupmenu from closing when i click it. I know
the simple hack is to just repopup the menu after the click but i
would like to keep the popupmenu structure intact before the click
(i.e. i might have gone down several subitems and i dont believe you
can repopup to the exact subitems state)
Here's one way of doing it for a popup on a form. Similar for other
objects.

procedure TForm1.FormCreate(Sender: TObject);
begin
// or set these in Object Inspector
PopUpMenu1.AutoPopup := false;
Form1.Popup := false;
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
MousePoint : TPoint;
begin
if (Button = mbRight) then begin
MousePoint := ClientToScreen(point(X, Y)); // convert to Screen co-
ordinates
PopUpMenu1.PopUp(MousePoint.X, MousePoint.Y); // needs screen co-
ords
end;
end;

Alan Lloyd
JJ
2009-02-17 16:08:48 UTC
Permalink
Post by b***@googlemail.com
Hi,
I am trying to stop my popupmenu from closing when i click it. I know
the simple hack is to just repopup the menu after the click but i
would like to keep the popupmenu structure intact before the click
(i.e. i might have gone down several subitems and i dont believe you
can repopup to the exact subitems state)
I notice TMS software has a component that can do this, but can anyone
save me some money and help me achieve the same thing without having
to buy it?
TAdvStickyPopupMenu -> http://www.tmssoftware.com/site/atbdev10.asp
Regards,
Chris
TAdvStickyPopupMenu doesn't use a standard popup menu. It only mimics
the standard popup menu in order to implement a "sticky" popup menu feature.

Similar method can be done using a TForm with bsNone BorderStyle. You'll
need to assign TForm OnPaint event in order to draw the popup menu modal
border using the DrawFrameControl Windows API function. The form should
contains one or more TLabel components to represent each menu item. Each
TLabel has its OnMouseOver event assigned in order to mimic the menu
selection by changing the TLabel Color and Font.Color.

To simplify things, create a new TForm decendant class where its
constructor prepares the required TLabels based on existing TPopupMenu
object.
c***@btinternet.com
2020-06-06 14:52:18 UTC
Permalink
It's a long time since this thread was active but I'll ask anyway.

I assume alang's Form1 is the application's original form, while jj's Form1 is a new form/unit?

alang: I don't see any Popup property for a TForm.

jj: I don't see any OnMouseOver event for a TLabel.

DrawFrameControl draws a blank on RAD Studio's Help.

Any chance of a working example? :-)

Loading...