How can a TPopupMenu be aligned to the right hand side of a form? The problem is that there doesn't seem to be a way to get the width of the Popup menu before you call Popup(X, Y: Integer)
.
I'm trying to get a behavior similar to that of the system menu in Chrome.
The easiest solution would be to launch the popup menu yourself:
procedure TForm1.Panel1ContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
var
PopupPt: TPoint;
begin
PopupPt := ClientToScreen(Point(ClientWidth, 0));
TrackPopupMenu(PopupMenu1.Handle, TPM_RIGHTALIGN or TPM_TOPALIGN,
PopupPt.X, PopupPt.Y, 0, PopupList.Window, nil);
end;
See documentation for TrackPopupMenu
or TrackPopupMenuEx
for what various flags mean.
You could also just set Alignment
to paRight
and call
with ClientToScreen(Point(ClientWidth - 1, 0)) do
Popup(X, Y);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With