TPopupMenu 如何与表单的右侧对齐?问题是似乎没有办法在调用之前获取 Popup 菜单的宽度Popup(X, Y: Integer)
。
我试图获得类似于 Chrome 中系统菜单的行为。
最简单的解决方案是自己启动弹出菜单:
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;
请参阅文档以了解各种标志的含义TrackPopupMenu
或TrackPopupMenuEx
含义。
您也可以设置Alignment
为paRight
并调用
with ClientToScreen(Point(ClientWidth - 1, 0)) do
Popup(X, Y);